0

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.

Roma Kap
  • 517
  • 1
  • 8
  • 23
  • Possible duplicate of [How to run test methods in specific order in JUnit4?](http://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4) – Mureinik Oct 14 '16 at 11:22
  • Yes, i know about this thread. Solution with `@FixMethodOrder(MethodSorters.NAME_ASCENDING)` seems to be nice. But actually i either would do intergration-test with a test-suite and no modul-test. Even on of much answers talks same. – Roma Kap Oct 15 '16 at 13:59

0 Answers0