What's the actual use of 'fail' in JUnit test case?

后端 未结 8 1142
长情又很酷
长情又很酷 2021-01-30 15:31

What\'s the actual use of \'fail\' in JUnit test case?

8条回答
  •  广开言路
    2021-01-30 15:57

    I've used it in the case where something may have gone awry in my @Before method.

    public Object obj;
    
    @Before
    public void setUp() {
        // Do some set up
        obj = new Object();
    }
    
    @Test
    public void testObjectManipulation() {
        if(obj == null) {
            fail("obj should not be null");
         }
    
        // Do some other valuable testing
    }
    

提交回复
热议问题