This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 52ec277  [SUREFIRE-1857] JUnit 5 report does not contain assertion 
failure message
52ec277 is described below

commit 52ec2773d168d35dcc681b184f72c1053a1b9f16
Author: Niklas Krieger <53957498+nk-cod...@users.noreply.github.com>
AuthorDate: Wed Nov 18 09:27:29 2020 +0100

    [SUREFIRE-1857] JUnit 5 report does not contain assertion failure message
---
 .../maven/surefire/its/JUnitPlatformEnginesIT.java | 32 ++++++++++
 .../surefire-1857-assertion-message/pom.xml        | 68 ++++++++++++++++++++++
 .../java/jira1857/AssertionFailureMessageTest.java | 33 +++++++++++
 .../surefire-1857-exception-message/pom.xml        | 68 ++++++++++++++++++++++
 .../test/java/jira1857/ExceptionMessageTest.java   | 30 ++++++++++
 .../surefire/junitplatform/RunListenerAdapter.java | 27 ++++++++-
 6 files changed, 256 insertions(+), 2 deletions(-)

diff --git 
a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java
 
b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java
index fbe2b36..a8ebe8b 100644
--- 
a/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java
+++ 
b/surefire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformEnginesIT.java
@@ -342,6 +342,38 @@ public class JUnitPlatformEnginesIT extends 
SurefireJUnit4IntegrationTestCase
     }
 
     @Test
+    public void testJupiterEngineWithAssertionsFailMessage()
+    {
+        OutputValidator validator = unpack( "surefire-1857-assertion-message", 
"-" + jupiter )
+                .setTestToRun( "AssertionFailureMessageTest" )
+                .sysProp( "junit5.version", jupiter )
+                .maven()
+                .withFailure()
+                .executeTest()
+                .verifyTextInLog( "AssertionFailureMessageTest.failedTest:31" )
+                .assertTestSuiteResults( 1, 0, 1, 0 );
+
+        validator.getSurefireReportsFile( 
"TEST-jira1857.AssertionFailureMessageTest.xml", UTF_8 )
+                .assertContainsText( "message=\"fail_message\"" );
+    }
+
+    @Test
+    public void testJupiterEngineWithExceptionMessage()
+    {
+        OutputValidator validator = unpack( "surefire-1857-exception-message", 
"-" + jupiter )
+                .setTestToRun( "ExceptionMessageTest" )
+                .sysProp( "junit5.version", jupiter )
+                .maven()
+                .withFailure()
+                .executeTest()
+                .verifyTextInLog( "ExceptionMessageTest.errorTest:28" )
+                .assertTestSuiteResults( 1, 1, 0, 0 );
+
+        validator.getSurefireReportsFile( 
"TEST-jira1857.ExceptionMessageTest.xml", UTF_8 )
+                .assertContainsText( "message=\"error_message\"" );
+    }
+
+    @Test
     public void testJupiterEngineWithDisplayNames()
     {
         OutputValidator validator = unpack( "junit-platform-engine-jupiter", 
"-" + jupiter )
diff --git 
a/surefire-its/src/test/resources/surefire-1857-assertion-message/pom.xml 
b/surefire-its/src/test/resources/surefire-1857-assertion-message/pom.xml
new file mode 100644
index 0000000..460acaa
--- /dev/null
+++ b/surefire-its/src/test/resources/surefire-1857-assertion-message/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<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>surefire-1857-assertion-message</artifactId>
+    <version>1.0</version>
+    <name>Test for JUnit 5: Platform + Jupiter</name>
+
+    <properties>
+        
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
+        
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
+        
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <version>${junit5.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-params</artifactId>
+            <version>${junit5.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>${surefire.version}</version>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git 
a/surefire-its/src/test/resources/surefire-1857-assertion-message/src/test/java/jira1857/AssertionFailureMessageTest.java
 
b/surefire-its/src/test/resources/surefire-1857-assertion-message/src/test/java/jira1857/AssertionFailureMessageTest.java
new file mode 100644
index 0000000..60648cb
--- /dev/null
+++ 
b/surefire-its/src/test/resources/surefire-1857-assertion-message/src/test/java/jira1857/AssertionFailureMessageTest.java
@@ -0,0 +1,33 @@
+package jira1857;
+
+/*
+ * 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.
+ */
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+class AssertionFailureMessageTest
+{
+    @Test
+    void failedTest()
+    {
+        fail( "fail_message" );
+    }
+}
diff --git 
a/surefire-its/src/test/resources/surefire-1857-exception-message/pom.xml 
b/surefire-its/src/test/resources/surefire-1857-exception-message/pom.xml
new file mode 100644
index 0000000..babb235
--- /dev/null
+++ b/surefire-its/src/test/resources/surefire-1857-exception-message/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<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>surefire-1857-exception-message</artifactId>
+    <version>1.0</version>
+    <name>Test for JUnit 5: Platform + Jupiter</name>
+
+    <properties>
+        
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
+        
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
+        
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <version>${junit5.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-params</artifactId>
+            <version>${junit5.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>${surefire.version}</version>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git 
a/surefire-its/src/test/resources/surefire-1857-exception-message/src/test/java/jira1857/ExceptionMessageTest.java
 
b/surefire-its/src/test/resources/surefire-1857-exception-message/src/test/java/jira1857/ExceptionMessageTest.java
new file mode 100644
index 0000000..8e31699
--- /dev/null
+++ 
b/surefire-its/src/test/resources/surefire-1857-exception-message/src/test/java/jira1857/ExceptionMessageTest.java
@@ -0,0 +1,30 @@
+package jira1857;
+
+/*
+ * 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.
+ */
+
+import org.junit.jupiter.api.Test;
+
+class ExceptionMessageTest
+{
+    @Test
+    void errorTest() {
+        throw new RuntimeException( "error_message" );
+    }
+}
diff --git 
a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
 
b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
index c0cfed2..b193ba5 100644
--- 
a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
+++ 
b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 
 import org.apache.maven.surefire.report.PojoStackTraceWriter;
 import org.apache.maven.surefire.api.report.RunListener;
+import org.apache.maven.surefire.api.report.SafeThrowable;
 import org.apache.maven.surefire.api.report.SimpleReportEntry;
 import org.apache.maven.surefire.api.report.StackTraceWriter;
 import org.junit.platform.engine.TestExecutionResult;
@@ -124,13 +125,16 @@ final class RunListenerAdapter
                     }
                     break;
                 case FAILED:
+                    String reason = safeGetMessage( 
testExecutionResult.getThrowable().orElse( null ) );
+                    SimpleReportEntry reportEntry = createReportEntry( 
testIdentifier, testExecutionResult, 
+                            reason, elapsed );
                     if ( isAssertionError )
                     {
-                        runListener.testFailed( createReportEntry( 
testIdentifier, testExecutionResult, elapsed ) );
+                        runListener.testFailed( reportEntry );
                     }
                     else
                     {
-                        runListener.testError( createReportEntry( 
testIdentifier, testExecutionResult, elapsed ) );
+                        runListener.testError( reportEntry );
                     }
                     if ( isClass || isRootContainer )
                     {
@@ -160,6 +164,19 @@ final class RunListenerAdapter
         return startTime == null ? null : (int) ( endTime - startTime );
     }
 
+    private String safeGetMessage( Throwable throwable )
+    {
+        try
+        {
+            SafeThrowable t = throwable == null ? null : new SafeThrowable( 
throwable );
+            return t == null ? null : t.getMessage();
+        }
+        catch ( Throwable t )
+        {
+            return t.getMessage();
+        }
+    }
+
     @Override
     public void executionSkipped( TestIdentifier testIdentifier, String reason 
)
     {
@@ -204,6 +221,12 @@ final class RunListenerAdapter
         return createReportEntry( testIdentifier, testExecutionResult, 
emptyMap(), null, elapsedTime );
     }
 
+    private SimpleReportEntry createReportEntry( TestIdentifier testIdentifier,
+            TestExecutionResult testExecutionResult, String reason, Integer 
elapsedTime )
+    {
+        return createReportEntry( testIdentifier, testExecutionResult, 
emptyMap(), reason, elapsedTime );
+    }
+
     private StackTraceWriter toStackTraceWriter( String realClassName, String 
realMethodName,
                                                  TestExecutionResult 
testExecutionResult )
     {

Reply via email to