samedi 8 avril 2017

How to test a java test class?

I have created a JUnit conformance java test class. It basically runs as a presubmit test whenever a developer submitting a code.

@RunWith(JUnit4.class)
public class ConformanceTest {

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

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

I would like to create a test for that class (in this case ConformanceTestTest.java).

Do I have more elegant way rather than doing something like this

@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 */
    }
}    

Aucun commentaire:

Enregistrer un commentaire