简体   繁体   中英

How to make integration test fail when objectMapper throws exception

I am writing using JUNIT 5 junit-platform-console-standalone library to write integration tests. While reading a JSON object with Jackson, I wish to fail the test if there is any error in reading file.

Tried adding throws IOException to method signature but that doesn;t seem to work.

@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 ?  
    }
  });
}

You can use 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");
    }
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM