当objectMapper抛出异常时,如何使集成测试失败



我正在使用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");
}
});
}

最新更新