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

后端 未结 6 1241
无人及你
无人及你 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条回答
  •  萌比男神i
    2020-12-02 17:29

    Another option is the observable pattern in conjunction with lambda expressions. You can use something like the above.

    public class MyTestClass {
    
        private final List> AFTER_EVENT = new ArrayList<>();
    
        @After
        public void tearDown() {
            AFTER_EVENT.stream().forEach(c -> c.accept(this));
        }
    
        @Test
        public void testCase() {
            //=> Arrange
            AFTER_EVENT.add((o) -> {
                // do something after an assertion fail.
            }));
    
            //=> Act
    
            //=> Assert
            Assert.assertTrue(false);
        }
    }
    

提交回复
热议问题