-
Notifications
You must be signed in to change notification settings - Fork 543
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
[SUREFIRE-2298] fix xml output with junit 5 nested classes #828
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.surefire.its.jiras; | ||
|
||
import org.apache.maven.surefire.its.fixture.OutputValidator; | ||
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; | ||
import org.apache.maven.surefire.its.fixture.TestFile; | ||
import org.hamcrest.collection.IsIterableWithSize; | ||
import org.junit.Test; | ||
import org.w3c.dom.Node; | ||
import org.xmlunit.builder.Input; | ||
import org.xmlunit.xpath.JAXPXPathEngine; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
/** | ||
* | ||
*/ | ||
@SuppressWarnings("checkstyle:magicnumber") | ||
public class Surefire2298IT extends SurefireJUnit4IntegrationTestCase { | ||
@Test | ||
public void shouldNotCreateFilesForNested() throws Exception { | ||
OutputValidator outputValidator = unpack("surefire-2298-nested-class") | ||
.maven() | ||
.executeTest() | ||
.verifyTextInLog("BUILD SUCCESS") | ||
.assertTestSuiteResults(4, 0, 0, 0); | ||
|
||
outputValidator | ||
.getSurefireReportsXmlFile("io.olamy.BaseNestedTest$Inner.txt") | ||
.assertFileNotExists(); | ||
|
||
TestFile xmlReportFile = outputValidator.getSurefireReportsXmlFile("TEST-io.olamy.FirstNestedTest.xml"); | ||
xmlReportFile.assertFileExists(); | ||
|
||
/** | ||
* <testsuite version="3.0.2" name="FirstNestedTest" time="0.019" tests="1" errors="0" skipped="0" failures="0"> | ||
* <testcase name="outerTest" classname="FirstNestedTest" time="0.007"/> | ||
* <testcase name="innerTest" classname="BaseNestedTest$Inner" time="0.001"/> | ||
* </testsuite> | ||
**/ | ||
Iterable<Node> ite = new JAXPXPathEngine() | ||
.selectNodes( | ||
"//testcase", Input.fromFile(xmlReportFile.getFile()).build()); | ||
assertThat(ite, IsIterableWithSize.iterableWithSize(2)); | ||
ite = new JAXPXPathEngine() | ||
.selectNodes( | ||
"//testcase[@classname='FirstNestedTest']", | ||
Input.fromFile(xmlReportFile.getFile()).build()); | ||
assertThat(ite, IsIterableWithSize.iterableWithSize(1)); | ||
ite = new JAXPXPathEngine() | ||
.selectNodes( | ||
"//testcase[@classname='BaseNestedTest$Inner']", | ||
Input.fromFile(xmlReportFile.getFile()).build()); | ||
assertThat(ite, IsIterableWithSize.iterableWithSize(1)); | ||
|
||
xmlReportFile = outputValidator.getSurefireReportsXmlFile("TEST-io.olamy.SecondNestedTest.xml"); | ||
/** | ||
* <testsuite name="SecondNestedTest" time="0.003" tests="1" errors="0" skipped="0" failures="0"> | ||
* <testcase name="outerTest" classname="SecondNestedTest" time="0.001"/> | ||
* <testcase name="innerTest" classname="BaseNestedTest$Inner" time="0.0"/> | ||
* </testsuite> | ||
*/ | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.apache.maven.plugins.surefire</groupId> | ||
<artifactId>junit-platform-1.0.0-surefire-2298</artifactId> | ||
<version>1.0</version> | ||
<name>[SUREFIRE-2298] JUnit 5: Nested class in report</name> | ||
|
||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.release>17</maven.compiler.release> | ||
<junit.jupiter.execution.parallel.config.fixed.parallelism>2</junit.jupiter.execution.parallel.config.fixed.parallelism> | ||
<junit.jupiter.execution.parallel.config.strategy>fixed</junit.jupiter.execution.parallel.config.strategy> | ||
<junit.jupiter.execution.parallel.enabled>true</junit.jupiter.execution.parallel.enabled> | ||
<junit.jupiter.execution.parallel.mode.classes.default>concurrent</junit.jupiter.execution.parallel.mode.classes.default> | ||
<junit.jupiter.execution.parallel.mode.default>same_thread</junit.jupiter.execution.parallel.mode.default> | ||
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit</groupId> | ||
<artifactId>junit-bom</artifactId> | ||
<version>5.12.0</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Optionally: parameterized tests support --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.4.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.3.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.13.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire.version}</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.olamy; | ||
|
||
/** | ||
* Hello world! | ||
*/ | ||
public class App { | ||
public static void main(String[] args) { | ||
System.out.println("Hello World!"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.olamy; | ||
|
||
import org.junit.jupiter.api.*; | ||
|
||
abstract class BaseNestedTest { | ||
@Test | ||
void outerTest() { | ||
} | ||
|
||
@Nested | ||
class Inner { | ||
|
||
@Test | ||
void innerTest() { | ||
} | ||
} | ||
} | ||
|
||
class FirstNestedTest extends BaseNestedTest { | ||
} | ||
|
||
class SecondNestedTest extends BaseNestedTest { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import org.apache.maven.surefire.report.RunModeSetter; | ||
import org.junit.platform.engine.TestExecutionResult; | ||
import org.junit.platform.engine.TestSource; | ||
import org.junit.platform.engine.UniqueId; | ||
import org.junit.platform.engine.support.descriptor.ClassSource; | ||
import org.junit.platform.engine.support.descriptor.MethodSource; | ||
import org.junit.platform.launcher.TestExecutionListener; | ||
|
@@ -216,11 +217,25 @@ private SimpleReportEntry createReportEntry( | |
String reason, | ||
Integer elapsedTime) { | ||
String[] classMethodName = toClassMethodName(testIdentifier); | ||
String className = classMethodName[0]; | ||
|
||
Optional<UniqueId.Segment> classSegment = testIdentifier.getUniqueIdObject().getSegments().stream() | ||
.filter(segment -> "class".equals(segment.getType())) | ||
.findFirst(); | ||
Comment on lines
+221
to
+223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't parse the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, Cucumber was also broken by the last patch, so the alternative heuristic should be used. |
||
|
||
String className; | ||
if (classSegment.isPresent()) { | ||
className = classSegment.get().getValue(); | ||
} else { | ||
className = classMethodName[0]; | ||
} | ||
|
||
String classText = classMethodName[1]; | ||
if (Objects.equals(className, classText)) { | ||
classText = null; | ||
} | ||
|
||
classText = classMethodName[0]; // testIdentifier.getLegacyReportingName(); | ||
|
||
boolean failed = testExecutionResult == null || testExecutionResult.getStatus() == FAILED; | ||
String methodName = failed || testIdentifier.isTest() ? classMethodName[2] : null; | ||
String methodText = failed || testIdentifier.isTest() ? classMethodName[3] : null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha you're too fast :)