vendredi 14 octobre 2016

Set test method order by TestSuite

there are several topics about how test method order could be created, but i have some trouble.

I have simply Junit 4.11 TestClass:

public class ServiceTest {

    @BeforeClass
    public static void setUp() throws IllegalArgumentException, IOException {

        try {

            service = new Service("myService");

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Test
    public void testA {

        boolean isConnected = false;
        try {
            isConnected = service.initialService();
            assertEquals(true, isConnected);

        } catch (Exception e) {
            e.printStackTrace();
            assertEquals(true, isConnected);
        }
    }

    @Test
    public void testB {

        try {
            //exec some methods....
            assertEquals(true, isConnected);

        } catch (Exception e) {
            e.printStackTrace();
            assertEquals(true, isConnected);

        }
    }
}

The order of testmethod excution must be testA, testB.

Because of that, i´ve created Testsuite:

@RunWith(MySuite.class)
@SuiteClasses({ EwsServiceTest.class })

public class TestSuite {


}

At next i´ve defined Testrunner, which gives me methods testA and testB

public class MySuite extends Suite {

    private Method[] children= null;

    protected MySuite(Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {

        super(klass, suiteClasses);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected List<Runner> getChildren() {
        //collect testA and testB methods
        children = super.getChildren().get(0).getClass().getMethods();

        return super.getChildren();
    }

    @Override
    protected void runChild(Runner runner, RunNotifier notifier) {
        super.runChild(runner, notifier);
    }
}

How and within which introduced class can i set method-order like.

Aucun commentaire:

Enregistrer un commentaire