1
votes

I am running my test suite through testNG xml. Here is the xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" data-provider-thread-count="4" parallel="methods">
  <test name="Test" group-by-instances="true" parallel="instances">
    <classes>
      <class name="packageName"></class>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

I am using the data-provider with annotation parallel=true. I have like 2000 test cases which runs in a loop through one test case with different data. The test runs well when its not parallel. When i try to run the test in parallel, in 4 threads, the before and after method gets executed in the same thread, however my test method is allocated altogether different thread. How do i make sure that for a test case, before method , after method and test all run in the same thread for a test instance.

1
See Reporter.java:28-31. The BeforeTest, Test, and AfterTest methods always run in the same thread. You can test this by using Thread.currentThread(). See gist.mfulton26

1 Answers

0
votes

Did you tried singleThreaded? like below example

@Test(singleThreaded = true)

 public class DemoForMethodOrdering {

  ///implementation here
}

please find information about singleThreaded in testng doc here

Thank You, Murali