We used testng with java to perform integration tests for our code. We executed a listener to run the test as follows: -
public class TestExecutionListener implements IInvokedMethodListener { @Override public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) { System.out.println("Testing : " + iInvokedMethod.getTestMethod().getMethodName()); } @Override public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) { System.out.println("Successfully Tested : " + iInvokedMethod.getTestMethod().getMethodName()); } }
Our testng.xml is defined as: -
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="TestSuite" verbose="1" parallel="classes" thread-count="10"> <listeners> <listener class-name="core.TestExecutionListener"/> </listeners> <test name="IntegrationTests"> <classes> <class name="test.SomeTest1"/> <class name="test.SomeTest2"/> <class name="test.SomeTest3"/> <class name="test.SomeTest4"/> ... There are more than 20 classes </classes> </test> </suite>
When we run the tests, the output we get is as follows:
Testing : SomeTest1Method1 Testing : SomeTest2Method2 Testing : SomeTest4Method5 Successfully Tested : SomeTest2Method2 Successfully Tested : SomeTest4Method5
while we expect the output to be: -
Testing : SomeTest1Method1 Successfully Tested : SomeTest1Method1 Testing : SomeTest2Method2 Successfully Tested : SomeTest2Method2 Testing : SomeTest4Method5 Successfully Tested : SomeTest4Method5
Guess this because of the parallel="classes" attribute in xml, since changing it to false gives the desired result. But, as is obvious, a change in execution requires much more time than parallel execution.
Is there a way to run these tests in parallel, but still get this output in sequence?
java unit-testing integration-testing testng
nullpointer
source share