Skip to content

Commit 2e0c8bd

Browse files
committed
Ignore Config skips in xml reports
Closes #2886 TestNG by design excludes suite level configs When there is inheritance involved and multiple Children of the same base class are included in a suite. But when reporting the results as xml TestNG is not excluding these configs from the reports. Fixed this discrepancy.
1 parent ff5843a commit 2e0c8bd

File tree

6 files changed

+54
-10
lines changed

6 files changed

+54
-10
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Fixed: GITHUB-2862: Allow test classes to define "configfailurepolicy" at a per
1111
Fixed: GITHUB-2796: Option for onAfterClass to run after @AfterClass (Oliver Hughes)
1212
Fixed: GITHUB-2857: XmlTest index is not set for test suites invoked with YAML (Sergei Baranov)
1313
Fixed: GITHUB-2880: Before configuration and before invocation set 'SKIP' when beforeMethod is 'skip' (Bob Shi)
14+
Fixed: GITHUB-2886: testng-results xml reports config skips from base classes as ignored (Krishnan Mahadevan)
1415

1516
7.7.1
1617
Fixed: GITHUB-2854: overloaded assertEquals methods do not work from Groovy (Krishnan Mahadevan)

testng-core/src/main/java/org/testng/reporters/XMLReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void generateReport(
5555
}
5656
skipped += skippedPerTest;
5757
retried += retriedPerTest;
58-
ignored += testContext.getExcludedMethods().size();
58+
ignored += testContext.getExcludedMethods().stream().filter(ITestNGMethod::isTest).count();
5959
}
6060
}
6161

testng-core/src/test/java/test/reports/XmlReporterTest.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import org.testng.internal.WrappedTestNGMethod;
2323
import org.testng.reporters.RuntimeBehavior;
2424
import org.w3c.dom.Document;
25+
import org.w3c.dom.Node;
2526
import test.SimpleBaseTest;
2627
import test.reports.issue2171.TestClassExample;
28+
import test.reports.issue2886.HydeTestSample;
29+
import test.reports.issue2886.JekyllTestSample;
2730
import test.simple.SimpleSample;
2831

2932
public class XmlReporterTest extends SimpleBaseTest {
@@ -60,7 +63,7 @@ public void ensureStackTraceHasLineFeedsTest() throws Exception {
6063

6164
@Test(description = "GITHUB-2171")
6265
public void ensureCustomisationOfReportIsSupported() throws Exception {
63-
File file = runTest(TestClassExample.class, "issue_2171.xml");
66+
File file = runTest("issue_2171.xml", null, TestClassExample.class);
6467
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
6568
DocumentBuilder builder = factory.newDocumentBuilder();
6669
Document doc = builder.parse(file);
@@ -74,7 +77,6 @@ public void ensureCustomisationOfReportIsSupported() throws Exception {
7477
public void ensureReportGenerationWhenTestMethodIsWrappedWithWrappedTestNGMethod() {
7578
File file =
7679
runTest(
77-
SimpleSample.class,
7880
testng ->
7981
testng.setMethodInterceptor(
8082
(methods, context) ->
@@ -88,19 +90,34 @@ public void ensureReportGenerationWhenTestMethodIsWrappedWithWrappedTestNGMethod
8890
assertThat(file.exists()).isTrue();
8991
}
9092

91-
private static File runTest(Class<?> clazz) {
92-
return runTest(clazz, RuntimeBehavior.FILE_NAME, null);
93+
@Test(description = "GITHUB-2886")
94+
public void ensureConfigurationMethodsAreNotCountedAsSkippedInXmlReports() throws Exception {
95+
File file =
96+
runTest(RuntimeBehavior.FILE_NAME, null, JekyllTestSample.class, HydeTestSample.class);
97+
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
98+
DocumentBuilder builder = factory.newDocumentBuilder();
99+
Document doc = builder.parse(file);
100+
XPath xPath = XPathFactory.newInstance().newXPath();
101+
Node node = (Node) xPath.compile("/testng-results").evaluate(doc, XPathConstants.NODE);
102+
int ignored = Integer.parseInt(node.getAttributes().getNamedItem("ignored").getNodeValue());
103+
int total = Integer.parseInt(node.getAttributes().getNamedItem("total").getNodeValue());
104+
int passed = Integer.parseInt(node.getAttributes().getNamedItem("passed").getNodeValue());
105+
int failed = Integer.parseInt(node.getAttributes().getNamedItem("failed").getNodeValue());
106+
assertThat(ignored).isZero();
107+
assertThat(total).isEqualTo(2);
108+
assertThat(passed).isEqualTo(2);
109+
assertThat(failed).isZero();
93110
}
94111

95-
private static File runTest(Class<?> clazz, Consumer<TestNG> customizer) {
96-
return runTest(clazz, RuntimeBehavior.FILE_NAME, customizer);
112+
private static File runTest(Class<?> clazz) {
113+
return runTest(RuntimeBehavior.FILE_NAME, null, clazz);
97114
}
98115

99-
private static File runTest(Class<?> clazz, String fileName) {
100-
return runTest(clazz, fileName, null);
116+
private static File runTest(Consumer<TestNG> customizer) {
117+
return runTest(RuntimeBehavior.FILE_NAME, customizer, SimpleSample.class);
101118
}
102119

103-
private static File runTest(Class<?> clazz, String fileName, Consumer<TestNG> customizer) {
120+
private static File runTest(String fileName, Consumer<TestNG> customizer, Class<?>... clazz) {
104121
String suiteName = UUID.randomUUID().toString();
105122
File fileLocation = createDirInTempDir(suiteName);
106123
TestNG testng = create(fileLocation.toPath(), clazz);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test.reports.issue2886;
2+
3+
import org.testng.annotations.BeforeSuite;
4+
5+
public class BaseClassSample {
6+
7+
@BeforeSuite
8+
public void beforeSuite() {}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test.reports.issue2886;
2+
3+
import org.testng.annotations.Test;
4+
5+
public class HydeTestSample extends BaseClassSample {
6+
7+
@Test
8+
public void rogueBehaviourTest() {}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package test.reports.issue2886;
2+
3+
import org.testng.annotations.Test;
4+
5+
public class JekyllTestSample extends BaseClassSample {
6+
@Test
7+
public void gentleBehaviourTest() {}
8+
}

0 commit comments

Comments
 (0)