Search code examples
javamavenweb-testing

How do I run tests using maven if I have multiple test classes with multiple tests in them which are prioritized?


I have 6 test classes, in each I have around 5 tests, which are prioritized. When I run the test suit using maven, the test classes are combined somehow. While the tests are not finished from a test class, another one starts, and fails my tests. Is there a way, to run 1 test class with all of its tests first, and to run the second class after the first one is finished and so on? Note: I run the test using a mvn command in Terminal.


Solution

  • I have around 5 tests, which are prioritized

    Probably you are using TestNG, having something like this for every test method:

    @Test( priority = 1 )
    

    If this is the case, you should add this as a tag because it's quite relevant.

    the test classes are combined somehow

    Probably you run them in parallel.

    Is there a way, to run 1 test class with all of its tests first, and to run the second class after the first one is finished and so on

    Yes. Run the classes sequentially!

    Find the XML file like testng.xml where you defined the test suite. It should contain something like this:

    <suite name="YourSuite" parallel="classes" thread-count="6">
    

    Remove parallel="classes" thread-count="6" to achieve what you described above.

    See TestNG - parallel tests for other details.