-2
我從我的代碼獲得在單元測試expected:<interface java.sql.Connection> but was:<class com.mysql.jdbc.JDBC4Connection>
不能理解警告消息:預期:<接口java.sql.Connection中>卻被:<類com.mysql.jdbc.JDBC4Connection>
此消息:
@Test
public void connectionTest() throws SQLException{
Connection conn = ConnectionManager.createConnection();
assertEquals(Connection.class, conn.getClass());
conn.close();
}
我的模擬類用於獲取連接:
public class ConnectionManager {
@SuppressWarnings("unused")
public static Connection createConnection() throws SQLException {
String url = "jdbc:mysql://localhost:3306/library";
String name = "root";
String password = "root";
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url, name, password);
} catch (ClassNotFoundException e) {
if (connection != null){
connection.close();
}
throw new SQLException(e);
}
return connection;
}
}
什麼是錯我的代碼?
請不要繞過質量過濾器。 – SLaks
你爲什麼要測試編譯器? – SLaks