[
https://issues.apache.org/jira/browse/SUREFIRE-1832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17178469#comment-17178469
]
Tibor Digana commented on SUREFIRE-1832:
----------------------------------------
I have checked it out with the latest version. I did not have time to search
the fix in JIRA and the version, simply used the latest one.
I do not have time to backport the fix to 2.22.3 but you [~froque] may try if
you like.
{noformat}
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ surefire-junit4
---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running test.TestWithRuleThatThrows
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.152 s
<<< FAILURE! - in test.TestWithRuleThatThrows
[ERROR] test.TestWithRuleThatThrows.shouldAnswerWithTrue Time elapsed: 0.023 s
<<< ERROR!
java.lang.RuntimeException: some problem
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] TestWithRuleThatThrows.shouldAnswerWithTrue » Runtime some problem
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
{noformat}
> Exceptions thrown in TestRules are ignored in parallel test execution
> ---------------------------------------------------------------------
>
> Key: SUREFIRE-1832
> URL: https://issues.apache.org/jira/browse/SUREFIRE-1832
> Project: Maven Surefire
> Issue Type: Bug
> Affects Versions: 2.22.2
> Environment: $ mvn --version
>
> Apache Maven 3.6.3
> Maven home: /usr/share/maven
> Java version: 1.8.0_265, vendor: Private Build, runtime:
> /usr/lib/jvm/java-8-openjdk-amd64/jre
> Default locale: en_US, platform encoding: UTF-8
> OS name: "linux", version: "5.4.0-42-generic", arch: "amd64", family: "unix"
> $ java -version
> openjdk version "1.8.0_265"
> OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
> OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
> Reporter: Filipe Roque
> Assignee: Tibor Digana
> Priority: Major
>
> when an exception is thrown in a JUnit TestRule and maven-surefire-plugin ins
> run in parallel mode, the exception is ignored and does not break the build.
>
> *Unit test*
> {code:java}
> import static org.junit.Assert.assertTrue;
> import org.junit.Rule;
> import org.junit.Test;
> import org.junit.rules.TestRule;
> import org.junit.runner.Description;
> import org.junit.runners.model.Statement;
> public class TestWithRuleThatThrows
> {
> @Rule
> public TestRuleThatThrows testRuleThatThrows = new TestRuleThatThrows();
> @Test
> public void shouldAnswerWithTrue()
> {
> assertTrue( true );
> }
> public static class TestRuleThatThrows implements TestRule {
> @Override
> public Statement apply(final Statement base, final Description
> description) {
> throw new RuntimeException("some problem");
> }
> }
> }
> {code}
> *pom.xml*
> {code:xml}
> <?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>com.mycompany.app</groupId>
> <artifactId>my-app</artifactId>
> <version>1.0-SNAPSHOT</version>
> <name>my-app</name>
> <!-- FIXME change it to the project's website -->
> <url>http://www.example.com</url>
> <properties>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> <maven.compiler.source>1.8</maven.compiler.source>
> <maven.compiler.target>1.8</maven.compiler.target>
> </properties>
> <dependencies>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.11</version>
> <scope>test</scope>
> </dependency>
> </dependencies>
> </project>
> {code}
>
> {code:java}
> $ mvn org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test > /dev/null
> ; echo $?
> 1
> $ mvn org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test
> -Dparallel=all -DthreadCount=1 > /dev/null ; echo $?
>
> 0
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)