-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestNG.xml doesn't honour Parallel value of a clone. #2866
Comments
@kamal-kaur04 - Would you be willing to help raise a PR to fix this ? You just need to add the changes to https://github.com/cbeust/testng/blob/master/testng-core-api/src/main/java/org/testng/xml/XmlTest.java#L418 |
@krmahadevan But I can see |
@kamal-kaur04 - Yeah my bad. I missed seeing that. But I am not sure i still understand the problem. Here's a sample that I used to reproduce this and I am not able to. ClassA and ClassB look exactly like thisimport org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.annotations.Test;
public class ClassA {
@Test
public void foo() {
ITestResult itr = Reporter.getCurrentTestResult();
String msg = String.format("<%s> test case %s running on Thread # %s",
itr.getTestContext().getName(), itr.getMethod().getQualifiedName(),
Thread.currentThread().getId());
System.err.println(msg);
}
} My listenerimport java.util.List;
import org.testng.IAlterSuiteListener;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
public class SuiteChanger implements IAlterSuiteListener {
@Override
public void alter(List<XmlSuite> suites) {
XmlTest original = suites.get(0).getTests().get(0);
XmlTest cloned = (XmlTest) original.clone();
cloned.setName("cloned_test");
}
} My Sample test caseimport java.util.Arrays;
import java.util.Collections;
import org.testng.TestNG;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlSuite.ParallelMode;
import org.testng.xml.XmlTest;
public class SampleTestCase {
public static void main(String[] args) {
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setName("sample_suite");
XmlTest original = new XmlTest(xmlSuite);
original.setName("original_test");
original.setParallel(ParallelMode.CLASSES);
original.setClasses(Arrays.asList(new XmlClass(ClassA.class), new XmlClass(ClassB.class)));
xmlSuite.setListeners(Collections.singletonList(SuiteChanger.class.getName()));
TestNG testng = new TestNG();
testng.setXmlSuites(Collections.singletonList(xmlSuite));
testng.setVerbose(2);
testng.run();
}
} Here's the output SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
<original_test> test case com.rationaleemotions.issue2866.ClassA.foo running on Thread # 17
<original_test> test case com.rationaleemotions.issue2866.ClassB.foo running on Thread # 18
PASSED: com.rationaleemotions.issue2866.ClassA.foo
PASSED: com.rationaleemotions.issue2866.ClassB.foo
===============================================
original_test
Tests run: 2, Failures: 0, Skips: 0
===============================================
<cloned_test> test case com.rationaleemotions.issue2866.ClassA.foo running on Thread # 19
<cloned_test> test case com.rationaleemotions.issue2866.ClassB.foo running on Thread # 20
PASSED: com.rationaleemotions.issue2866.ClassA.foo
PASSED: com.rationaleemotions.issue2866.ClassB.foo
===============================================
cloned_test
Tests run: 2, Failures: 0, Skips: 0
===============================================
===============================================
sample_suite
Total tests run: 4, Passes: 4, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0
|
I think I was setting threadCount as 1 at SuiteLevel that's why it was getting inherited by particular test. Any reason why suite Level thread-count takes priority if Test already has thread-count?
|
That is because the |
Ack, I'll share a PR for the fix. Thanks @krmahadevan |
Sure. Please don't forget the following
Some more help on contributing to TestNG https://github.com/cbeust/testng/blob/master/.github/CONTRIBUTING.md#working-with-the-codebase |
TestNG Version
Currently, I'm using listener via ServiceLoader.
Listener
testng.xml
Expected behavior
The two classes should run in parallel.
Actual behavior
But these classes run sequentially.
Is the issue reproducible on runner?
Test case sample
Contribution guidelines
Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.
The text was updated successfully, but these errors were encountered: