Continuing test execution in junit4 even when one of the asserts fails

后端 未结 6 1249
无人及你
无人及你 2020-12-02 16:55

I have my existing framework built up using Jfunc which provides a facility to continue exection even when one of the asserts in the test case fails. Jfunc uses junit 3.x f

6条回答
  •  感动是毒
    2020-12-02 17:12

    You can also use assertj - soft assertion

    @Test
    public void testCollectErrors(){
       SoftAssertions softly = new SoftAssertions();
       softly.assertThat(true).isFalse();
       softly.assertThat(false).isTrue();
       // Don't forget to call SoftAssertions global verification !
       softly.assertAll();
    }
    

    Also exist other way to use it without manually invoke softly.assertAll();

    1. with rule
    2. with autoclosable
    3. Using the static assertSoftly method

提交回复
热议问题