1

I am experimenting how to run tests in parallel with maven surefire and testng. However, the configuration seems not very straightforward and I can't make it work. Below are my dummy tests.

@Log4j
public class DummyTest {
    @Test
    public void test_1() throws InterruptedException {
        log.info("test 1 started");
        Thread.sleep( 3000 );
        assertTrue(true);
        log.info("test 1 ended");
    }

    @Test
    public void test_2() throws InterruptedException {
        log.info("test 2 started");
        Thread.sleep( 5000 );
        assertTrue(true);
        log.info("test 2 ended");
    }
}

//------------------------------------
public class Dummy2Test {
    @Test
    public void test_1() throws InterruptedException {
        log.info("test 1 started");
        Thread.sleep( 3000 );
        assertTrue(true);
        log.info("test 1 ended");
    }

    @Test
    public void test_2() throws InterruptedException {
        log.info("test 2 started");
        Thread.sleep( 5000 );
        assertTrue(true);
        log.info("test 2 ended");
    }
}

And this is my surefire configuration:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <parallel>all</parallel>
                <threadCount>10</threadCount>
            </configuration>
        </plugin>

The tests are essentially running sequentially. Here are logs as evidence:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.tns.ct.tests.Dummy2Test
Configuring TestNG with: TestNG652Configurator
2014-10-14 18:51:18 INFO  com.tns.ct.tests.Dummy2Test.test_1():12 - test 1 started
2014-10-14 18:51:21 INFO  com.tns.ct.tests.Dummy2Test.test_1():15 - test 1 ended
2014-10-14 18:51:21 INFO  com.tns.ct.tests.Dummy2Test.test_2():20 - test 2 started
2014-10-14 18:51:26 INFO  com.tns.ct.tests.Dummy2Test.test_2():23 - test 2 ended
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.316 sec - in com.tns.ct.tests.Dummy2Test
Running com.tns.ct.tests.DummyTest
Configuring TestNG with: TestNG652Configurator
2014-10-14 18:51:27 INFO  com.tns.ct.tests.DummyTest.test_1():12 - test 1 started
2014-10-14 18:51:30 INFO  com.tns.ct.tests.DummyTest.test_1():15 - test 1 ended
2014-10-14 18:51:30 INFO  com.tns.ct.tests.DummyTest.test_2():20 - test 2 started
2014-10-14 18:51:35 INFO  com.tns.ct.tests.DummyTest.test_2():23 - test 2 ended
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.318 sec - in com.tns.ct.tests.DummyTest

Results :

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

My intention is to run all tests (down to method level) in parallel. So, how can I achieve that?

JBT
  • 8,498
  • 18
  • 65
  • 104

1 Answers1

0

I don't think all is an option for TestNG. Try with <parallel>methods<\paralell> if you want all to testcases to be executed in parallel.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
  • 1
    I tried that. Unfortunately, it is not working very well. In any case, I have solved my problem by having a testng.xml where I specify parallel strategy. – JBT Oct 16 '14 at 17:46
  • So without a testng.xml , we cannot run the tests in parallel? I did try out the sample code and it worked fine for me without including a testng.xml file. I was able to run the test methods all in parallel. I tried with surefire 2.21.0 version and testng 6.8.21 – lostintranslation Apr 20 '18 at 11:27