apache / apache/maven-surefire
[SUREFIRE-1525] Exception in a @BeforeClass method in a JUnit suite class does not fail the build if ran in parallel
- Dominant language
- Java
- Stars
- 461
- Forks
- 588
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 19
Description
**[Ivan Syarov](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=isyarov)** opened **[SUREFIRE-1525](https://issues.apache.org/jira/browse/SUREFIRE-1525?redirect=false)** and commented
I have a `@BeforeClass` annotated method in a JUnit test suite class, and if an exception is thrown in the method, the parallel build either succeeds if the **-DfailIfNoTests** parameter is set to false or fails with "No tests were executed" if the parameter is set to true. If the build is started without the **parallel** parameter it fails as it should.
I used a simple project setup to reproduce. I have two test classes, each with one test method and a suite class:
**TestA.class**
```java
public class TestA {
@Test
public void test() {
System.out.println("TestA");
}
}
```
**TestB.class**
```java
public class TestB {
@Test
public void test() {
System.out.println("TestB");
}
}
```
**TestSuite.class**
```java
@RunWith(Suite.class)
@SuiteClasses({TestA.class, TestB.class})
public class TestSuite {
@BeforeClass
public static void setUp() {
throw new RuntimeException("ex");
}
}
```
If i execute:
mvn clean install -Dtest=TestSuite -Dparallel=classes -DthreadCount=2 -DfailIfNoTests=false
the build succeeds. If I omit the -DfailIfNoTests=false the build fails, but not because of the thrown exception, but with "No tests were executed!". If i omit the parallel parameter the build fails appropriately with "There are test failures."
The JUnit version is 4.12
The surefire plugin version is 2.19.1 - 2.21.0
---
**Affects:** 2.21.0
1 votes, 3 watchers
Contributor guide
Research direction
Start by reproducing the issue with TestA, TestB, TestSuite, JUnit 4.12, and the Maven commands using parallel and serial execution. Trace Surefire's parallel test execution and failIfNoTests handling; done means a @BeforeClass exception makes the parallel build fail with the test failure rather than succeeding or reporting no tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100