1

I have a testsuite say JunitTest1 and JunitTest2 as below,

@RunWith(Suite.class)
@SuiteClasses({ 
    com.sample.test1.class,
    com.sample.test2.class,
    com.sample.test3.class,
})

public class JunitTest1 {

}

@RunWith(Suite.class)
    @SuiteClasses({ 
        com.sample.xxx1.class,
        com.sample.xxx2.class,
        com.sample.xxx3.class,
    })

    public class JunitTest2 {

    }

I want to run both the testsuite in parallel but the test class inside the testsuite should run in the specified order. I have added the below plugin in maven pom.xml,

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20.1</version>
                <configuration>
                    <parallel>suites</parallel>
                    <threadCount>2</threadCount>
                    <!-- <forkCount>1</forkCount>
                    <reuseForks>true</reuseForks> -->
                </configuration>
            </plugin>

I have followed this link - http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html

I have tried all the possible combination for parallel tag like methods, classes, both, suites, suitesAndClasses, suitesAndMethods, classesAndMethods, all but nothing seems to solve my problem. The test suite are still running in sequential if i use suites and for other options the test classes in test suite are running in random order

Is there anything i am doing it wrong? can anyone please guide me to solve this issue ?

Jugi
  • 1,164
  • 3
  • 20
  • 42
  • Why do you need to run the suite in a specific order? This sounds like bad test, it should be possible to run them in any order – robjwilkins Dec 12 '17 at 17:16
  • @robjwilkins The test class are dependent. For example, an id will be generated in testcase1 and that needs to be used in subsequent test cases. – Jugi Dec 12 '17 at 18:42
  • So all the test class in test suite should run in the given order – Jugi Dec 12 '17 at 18:43
  • You shouldn't use test suites (simply remove them)...let maven-surefire-plugin do it's work.. – khmarbaise Dec 13 '17 at 07:21
  • The reason to use test suite is that i want to run the test classes in same order as i mentioned in my question – Jugi Dec 13 '17 at 14:28

1 Answers1

0

junit tests should be independent of one-another. junit does not provide a means to order tests to prevent you from writing tests which are dependent on other tests.

There are other SO threads on this topic:

How to run test methods in order with Junit

and

http://stackoverflow.com/questions/3693626/how-to-run-test-methods-in-specific-order-in-junit4

robjwilkins
  • 4,444
  • 3
  • 38
  • 51
  • I am able to run the test cases in order. I am looking for a solution to run the test class in the test suite to run in same order during parallel execution. For my above example, I want to run JunitTest1 and JunitTest2 in parallel and during the parallel execution, JunitTest1 should run test1, test2 and test3 and JunitTest2 should run in xxx1, xxx2 and xxx3 . I am not able to execute in this order during parallel execution via surefire plugin – Jugi Dec 12 '17 at 19:04