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

后端 未结 6 1237
无人及你
无人及你 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:20

    I use the ErrorCollector too but also use assertThat and place them in a try catch block.

    import static org.junit.Assert.*;
    import static org.hamcrest.Matchers.*;
    
    @Rule
    public ErrorCollector collector = new ErrorCollector();
    
    @Test
    public void calculatedValueShouldEqualExpected() {
        try {
            assertThat(calculatedValue(), is(expected));
        } catch (Throwable t) {
            collector.addError(t);
            // do something
        }
    }
    

提交回复
热议问题