How to avoid multiple asserts in a JUnit test?

前端 未结 7 781
故里飘歌
故里飘歌 2020-11-29 12:12

I have a DTO which I\'m populating from the request object, and the request object has many fields. I want to write a test to check if the populateDTO() method

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 12:49

    this construction help you to have 1 big assert (with small asserts inside)

    import static org.junit.jupiter.api.Assertions.assertAll;
    
    assertAll(
        () -> assertThat(actual1, is(expected)),
        () -> assertThat(actual2, is(expected))
    );
    

提交回复
热议问题