我想简单测试JDBC连接,我不使用框架,只使用JDBC和JUnit.我可以用JUnit执行此测试吗?我不知道如何测试加载驱动程序,请给我一些连接测试的例子.
连接客户端:
package newpackage.db;
import java.sql.Connection;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SqlConnection {
private Connection con;
private String name;
private String url;
private String password;
private String driver;
public SqlConnection() {
this.name = "root";
this.password = "12345";
this.url = "";
this.driver = "com.mysql.jdbc.Driver";
}
public Connection getConnection() {
try {
Class.forName(driver);
} catch (ClassNotFoundException ex) {
Logger.getLogger(SqlConnection.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
测试用例:
public void testDriverManager() {
SqlConnection conClient = new SqlConnection();
assertEquals(conClient.getConnection(),...);
or
assertTrue(conClient.getConnection(),...);
}