0

I have been searching for something like this, but all what I have found was Fixed test order or completely random.

I have this kind of a test structure:

// imports

@RunWith(Suite.class)

@Suite.SuiteClasses({
        // Tests
})

public class TestRunSuite {
}

and what do I want to do:

// imports

@RunWith(Suite.class)

@Suite.SuiteClasses({
        testToExecuteFirst.class,
        // Tests in random order
        testToExecuteLast.class
})

public class TestRunSuite {
}

or

Is there a way how to make TestSuite execute in the middle of 2 functions ? What do I mean:

authentificationSetUp();
// somehow calling TestRunSuite
authentificationSetUpBack();

The reason why do I want to do this, is that I need to change the timeout of authentification on one website, but the thing is, that I need to logged in as an admin and tests are for other roles. So instead of going through all of those tests and putting to each @BeforeClass and @AfterClass these 2 tests.

StyleZ
  • 1,276
  • 3
  • 11
  • 27

1 Answers1

1

You could simply add a @BeforeClass method and an @AfterClass method inside your TestRunSuite class.

@RunWith(Suite.class)
@Suite.SuiteClasses({
        // Tests
})

public class TestRunSuite {

    @BeforeClass
    public void authentificationSetUp() {
        //Your code
    }

    @AfterClass
    public void authentificationSetUpBack() {
        //Your code
    }

}
Lungu Daniel
  • 816
  • 2
  • 8
  • 15