Skip to content

JUnit tests not executed or failures with Junit 5 & Surefire >= 3.0.0-M4 #2331

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

Closed
void-spark opened this issue Jul 6, 2021 · 10 comments
Closed
Labels
🐛 bug Defect / Bug 🙏 help wanted Help wanted - not prioritized by core team thirdparty: surefire
Milestone

Comments

@void-spark
Copy link

void-spark commented Jul 6, 2021

Describe the bug
With the latest versions of the surefire plugin, no features are executed, or the run fails entirely.

To Reproduce
Steps to reproduce the behavior:
Use the example from: https://github.com/bonigarcia/mastering-junit5/tree/b19313dc1f6a1b7c4421e84ac9d6afd117c218d5/junit5-cucumber
Run it once, everything works fine (surefire 2.22.2):

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

In the POM, change surefire to 3.0.0-M3, all still good:

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

In the POM, change surefire to 3.0.0-M4, tests are executed (can check with stdout 'ADD' in steps), but not reported:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
ADD
ADD
ADD
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

In the POM, change surefire to 3.0.0-M5, tests are executed (can check with stdout 'ADD' in steps), but not reported,
and an error is logged:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[ERROR] jul 06, 2021 9:47:26 AM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
[ERROR] INFO: Loading JUnit Platform configuration parameters from classpath resource [file:/C:/workspace/IdeaProjects/junit5-cucumber/target/test-classes/junit-platform.properties].
ADD
ADD
ADD
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Context & Motivation
We just want to use Junit5 + Cucumber, but with the latest versions of everything it just doesn't work.
Since the results are not reported to surefire, it also doesn't fail on errors, so we don't notice if there's a problem.

Your Environment

  • Cucmber 6.10.4
  • Junit-Jupiter 5.7.2
  • Windows 10
  • Maven 3.8.1
@mpkorstanje
Copy link
Contributor

You may be expecting a bit too much from a milestone release.

That said, as you are using Cucumber through the JUnit Platform the problem is probably somewhere between Surefire and the JUnit Platform rather then Cucumber. You may want to file an issue there instead.

@mpkorstanje
Copy link
Contributor

And there is quite a few more bits of code that assume that tests have a class source.

@void-spark
Copy link
Author

I'll revert to an older surefire version for now then. Wasn't actually sure what -M meant, I know -RC and -Beta and such :)
We come up with too many acronyms..
Sounds like the surefire team isn't really paying attention to non class sources, I guess Cucumber is one of the few (if any) frameworks using that.
Since this doesn't seem to be a Cucumber issue I'll close this one with this comment.
I'll hold off on posting an issue with them for now, it makes more sense to me for someone who actually understands what's going on to do that :) (And I'm not very fond of their Jira system :) ).

@void-spark
Copy link
Author

And thank you for your attention, it's certainly appreciated :)

@mpkorstanje
Copy link
Contributor

Let's keep this open. Just in case some one else has time to do the leg work.

@mpkorstanje mpkorstanje reopened this Jul 9, 2021
@mpkorstanje mpkorstanje added 🐛 bug Defect / Bug thirdparty: surefire 🙏 help wanted Help wanted - not prioritized by core team labels Jul 11, 2021
@mpkorstanje
Copy link
Contributor

See:

@aSemy
Copy link

aSemy commented Aug 4, 2021

Ah, I've just found this issue. Thanks for making it.

I've discovered that excluding nothing and including all .java files results in one test running (even though I have ~250 scenarios. It's better than Tests run: 0...

[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
          <excludes>
            <!-- Don't exclude any @Test by default -->
            <exclude/>
          </excludes>
          <includes>
            <include>**/*.java</include>
          </includes>
        </configuration>
      </plugin>

I'm using the following dependencies

  • org.springframework.boot:spring-boot-starter-parent:2.5.3
  • org.springframework.boot:spring-boot-starter-test:2.5.3
  • org.junit.jupiter:junit-jupiter:5.7.2
  • org.junit.platform:junit-platform-launcher:5.7.2
  • io.cucumber:cucumber-java:6.10.4
  • io.cucumber:cucumber-junit-platform-engine:6.10.4
  • io.cucumber:cucumber-spring:6.10.4

and excluding junit vintage

org.junit.vintage:junit-vintage-engine

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Aug 4, 2021

This is not a problem with Cucumber. Please do not report additional instances. Do upvote the issue in the Surefire bug tracker:

https://issues.apache.org/jira/browse/SUREFIRE-1849

edit: @aSemy fixed the mistake in message. Cheers.

@cucumber cucumber deleted a comment from aSemy Aug 5, 2021
@mpkorstanje mpkorstanje added this to the v7.0.0 milestone Aug 10, 2021
@mpkorstanje
Copy link
Contributor

mpkorstanje commented Aug 16, 2021

With Cucumber v7 (not yet released) and JUnit 5.8 (not yet released) we will deprecate @Cucumber in favour of @Suite. This should coincidently fix the issue with Surefire > M4.

Add:

<dependency>
   <groupId>org.junit.platform</groupId>
   <artifactId>junit-platform-suite</artifactId>
   <version>${junit-platform.version}</version>
   <scope>test</scope>
</dependency>

Then use:

package com.example;

import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@Suite
@SelectClasspathResource("com/exmaple")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
public class RunCucumberTest {
}

To improve the readability of the reports provide the
cucumber.junit-platform.naming-strategy=long configuration parameter.

mpkorstanje added a commit that referenced this issue Aug 18, 2021
The CucumberJUnit Platform Engine has been updated to 1.8. With JUnit 5.8 comes 
the `junit-platform-suite` engine. This engine allows the 
[programmatic declaration of test suites](https://junit.org/junit5/docs/current/user-guide/#test-suite).

So it is now possible to write the following JUnit 4 test:

```java
package com.example;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(glue = "com.example.application", features = "classpath:com/example/application")
public class RunCucumberTest {

}
```

As a declarative JUnit 5 test suite: 

```java
package com.example;

import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@suite
@IncludeEngines("cucumber")
@SelectClasspathResource("com/example/application")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example.application")
public class RunCucumberTest {

}
```

In combination with the before-all and after-all hooks this allows for a
feature-complete migration from JUnit 4. And allows us to deprecate
the `@Cucumber` annotation in favour of `@Suite`.

Fixes: #2331
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug 🙏 help wanted Help wanted - not prioritized by core team thirdparty: surefire
Projects
None yet
Development

No branches or pull requests

3 participants