如何测试java测试类?

时间:2017-04-08 14:03:32

标签: java testing

我创建了一个JUnit一致性java测试类。当开发人员提交代码时,它基本上作为预提交测试运行。

@RunWith(JUnit4.class)
public class ConformanceTest {

    @Before
    public void setUp() {
        // implementation, e.g. reading from a flag
    }

    @Test
    public void testStuff() {
        // chekcing implementation
    }
}

我想为该类创建一个测试(在本例中为ConformanceTestTest.java)。

我是否有更优雅的方式,而不是做这样的事情

@RunWith(JUnit4.class)
public class ConformanceTestTest {

    @Test
    public void testTestStuff() {
        ConformanceTest test = new ConformanceTest();
        // Setting up the environment, e.g. setting the flag for conformance
        // test class

        /* Need to understand the ConformanceTest lifecycle 
        instead of testing 'testStuff()' only */
        test.setUp(); 

        assertException(AssertionError.class, test.testStuff());

        /* I might have to do test.tearDown() if there is any */
    }
}    

0 个答案:

没有答案