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.
BeforeTest
,Test
, andAfterTest
methods always run in the same thread. You can test this by usingThread.currentThread()
. See gist. – mfulton26