根本找不到模拟数据库连接的具体示例。首选Mockito。
public Connection getCon() throws SQLException, Exception {
Properties login = new Properties();
TimeZone timeZone = TimeZone.getTimeZone("GMT+2:00");
TimeZone.setDefault(timeZone);
Connection conn = null;
conn = DriverManager.getConnection(url, username, password);
return conn;
}
想要测试此方法。。。
您所需要的只是模拟静态类DriverManager。以下是您问题的答案:用Mockito 模拟静态方法