Skip to content
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

Ignore Config skips in xml reports #2887

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Fixed: GITHUB-2862: Allow test classes to define "configfailurepolicy" at a per
Fixed: GITHUB-2796: Option for onAfterClass to run after @AfterClass (Oliver Hughes)
Fixed: GITHUB-2857: XmlTest index is not set for test suites invoked with YAML (Sergei Baranov)
Fixed: GITHUB-2880: Before configuration and before invocation set 'SKIP' when beforeMethod is 'skip' (Bob Shi)
Fixed: GITHUB-2886: testng-results xml reports config skips from base classes as ignored (Krishnan Mahadevan)

7.7.1
Fixed: GITHUB-2854: overloaded assertEquals methods do not work from Groovy (Krishnan Mahadevan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void generateReport(
}
skipped += skippedPerTest;
retried += retriedPerTest;
ignored += testContext.getExcludedMethods().size();
ignored += testContext.getExcludedMethods().stream().filter(ITestNGMethod::isTest).count();
}
}

Expand Down
35 changes: 26 additions & 9 deletions testng-core/src/test/java/test/reports/XmlReporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import org.testng.internal.WrappedTestNGMethod;
import org.testng.reporters.RuntimeBehavior;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import test.SimpleBaseTest;
import test.reports.issue2171.TestClassExample;
import test.reports.issue2886.HydeTestSample;
import test.reports.issue2886.JekyllTestSample;
import test.simple.SimpleSample;

public class XmlReporterTest extends SimpleBaseTest {
Expand Down Expand Up @@ -60,7 +63,7 @@ public void ensureStackTraceHasLineFeedsTest() throws Exception {

@Test(description = "GITHUB-2171")
public void ensureCustomisationOfReportIsSupported() throws Exception {
File file = runTest(TestClassExample.class, "issue_2171.xml");
File file = runTest("issue_2171.xml", null, TestClassExample.class);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(file);
Expand All @@ -74,7 +77,6 @@ public void ensureCustomisationOfReportIsSupported() throws Exception {
public void ensureReportGenerationWhenTestMethodIsWrappedWithWrappedTestNGMethod() {
File file =
runTest(
SimpleSample.class,
testng ->
testng.setMethodInterceptor(
(methods, context) ->
Expand All @@ -88,19 +90,34 @@ public void ensureReportGenerationWhenTestMethodIsWrappedWithWrappedTestNGMethod
assertThat(file.exists()).isTrue();
}

private static File runTest(Class<?> clazz) {
return runTest(clazz, RuntimeBehavior.FILE_NAME, null);
@Test(description = "GITHUB-2886")
public void ensureConfigurationMethodsAreNotCountedAsSkippedInXmlReports() throws Exception {
File file =
runTest(RuntimeBehavior.FILE_NAME, null, JekyllTestSample.class, HydeTestSample.class);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(file);
XPath xPath = XPathFactory.newInstance().newXPath();
Node node = (Node) xPath.compile("/testng-results").evaluate(doc, XPathConstants.NODE);
int ignored = Integer.parseInt(node.getAttributes().getNamedItem("ignored").getNodeValue());
int total = Integer.parseInt(node.getAttributes().getNamedItem("total").getNodeValue());
int passed = Integer.parseInt(node.getAttributes().getNamedItem("passed").getNodeValue());
int failed = Integer.parseInt(node.getAttributes().getNamedItem("failed").getNodeValue());
assertThat(ignored).isZero();
assertThat(total).isEqualTo(2);
assertThat(passed).isEqualTo(2);
assertThat(failed).isZero();
}

private static File runTest(Class<?> clazz, Consumer<TestNG> customizer) {
return runTest(clazz, RuntimeBehavior.FILE_NAME, customizer);
private static File runTest(Class<?> clazz) {
return runTest(RuntimeBehavior.FILE_NAME, null, clazz);
}

private static File runTest(Class<?> clazz, String fileName) {
return runTest(clazz, fileName, null);
private static File runTest(Consumer<TestNG> customizer) {
return runTest(RuntimeBehavior.FILE_NAME, customizer, SimpleSample.class);
}

private static File runTest(Class<?> clazz, String fileName, Consumer<TestNG> customizer) {
private static File runTest(String fileName, Consumer<TestNG> customizer, Class<?>... clazz) {
String suiteName = UUID.randomUUID().toString();
File fileLocation = createDirInTempDir(suiteName);
TestNG testng = create(fileLocation.toPath(), clazz);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package test.reports.issue2886;

import org.testng.annotations.BeforeSuite;

public class BaseClassSample {

@BeforeSuite
public void beforeSuite() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package test.reports.issue2886;

import org.testng.annotations.Test;

public class HydeTestSample extends BaseClassSample {

@Test
public void rogueBehaviourTest() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package test.reports.issue2886;

import org.testng.annotations.Test;

public class JekyllTestSample extends BaseClassSample {
@Test
public void gentleBehaviourTest() {}
}