Michael
Michael

Reputation: 343

TestNG Parallel Test Run

I am trying to run a sample test project in parallel with TestNG. But it is being executed sequentially in one thread. Am I missing anything?

I have set parallel="tests" thread-count="2" attributes in the suite tag.

Any help would be much appreciated.

Java class:

public class ParallelSuiteTest {
    String testName = "";
    @BeforeTest
    @Parameters({ "test-name" })
    public void beforeTest(String testName) {
        this.testName = testName;
        long id = Thread.currentThread().getId();
        System.out.println("Before test " + testName + ". Thread id is: " + id);
    }

    @BeforeClass
    public void beforeClass() {
        long id = Thread.currentThread().getId();
        System.out.println("Before test-class " + testName + ". Thread id is: "
                + id);
    }

    @Test
    public void testMethodOne() {
        long id = Thread.currentThread().getId();
        System.out.println("Sample test-method " + testName
                + ". Thread id is: " + id);
    }

    @AfterClass
    public void afterClass() {
        long id = Thread.currentThread().getId();
        System.out.println("After test-method  " + testName
                + ". Thread id is: " + id);
    }

    @AfterTest
    public void afterTest() {
        long id = Thread.currentThread().getId();
        System.out.println("After test  " + testName + ". Thread id is: " + id);
    }
}

Testng XML:

<suite name="Test-class Suite" parallel="tests" thread-count="2">
    <test name="Test-class test 1">
        <parameter name="test-name" value="test-method One" />
        <classes>
            <class name="ParallelSuiteTest" />
        </classes>
    </test>
    <test name="Test-class test 2">
        <parameter name="test-name" value="test-method Two" />
        <classes>
            <class name="ParallelSuiteTest" />
        </classes>
    </test>
</suite>

Output:

.Before test test-method One. Thread id is: 1
Before test-class test-method One. Thread id is: 1
Sample test-method test-method One. Thread id is: 1
After test-method  test-method One. Thread id is: 1
After test  test-method One. Thread id is: 1
Before test test-method One. Thread id is: 1
Before test-class test-method One. Thread id is: 1
Sample test-method test-method One. Thread id is: 1
After test-method  test-method One. Thread id is: 1
After test  test-method One. Thread id is: 1

===============================================
Test-class Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================

Thanks.

Upvotes: 1

Views: 1682

Answers (1)

Michael
Michael

Reputation: 343

Ok.After investigating the issue, I found out that this is a regression that was introduced in TestNG library version 6.13. Here is a link to the issue: https://github.com/cbeust/testng/issues/1636

Changing TestNG version to 6.11 solved the issue.

Upvotes: 2

Related Questions