我正在使用JUNIT 5junit-platform-console-standalone
库编写集成测试。在使用Jackson读取JSON对象时,如果在读取文件时出现任何错误,我希望测试失败。
尝试向方法签名添加throws IOException,但没有;似乎不起作用。
@Test
void objectMapperTest(){
// reading file line by line
objname.foreach(obj -> {
try{
Result result = objectMapper.readValue(line,Result.class);
} catch(IOException e) {
//How to make the test fail ?
}
});
}
您可以使用fail()
@Test
void objectMapperTest(){
// reading file line by line
objname.foreach(obj -> {
try{
Result result = objectMapper.readValue(line,Result.class);
} catch(IOException e) {
Assertions.fail("Test failure message");
}
});
}