即使在抛出正确的异常后,java AssertThrows仍未能通过测试
@Test
void testConnectToInvalidUrl() {
model.setCredentials("cst8288", "8288");
assertThrows(SQLException.class,() -> model.connectTo("jdbc:mysql://localhost:3306/redditreader?useUnicode=true&serverTimezone=UTC&useSSL=falses"));
}
我试图测试这个方法,它通过输入错误的url连接到JUnit中的MySQL数据库,因为它会抛出一个SQLException,确实如此,但无论如何测试都会失败。以下是实际的方法:
public void connectTo(String url) {
try {
connection = DriverManager.getConnection(url, User, Pass);
} catch (SQLException e) {
e.printStackTrace();
}
}
引发的异常为:
java.sql.SQLException: The connection property 'useSSL' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'falses' is not in this set.
我知道最后会有额外的问题,但既然是SQLException,assertThrows不应该通过测试吗
共 (0) 个答案