cucumber / cucumber-jvm

Cucumber for the JVM
https://cucumber.io
MIT License
2.69k stars 2.02k forks source link

No test executed with `cucumber-junit-platform-engine` for JUnit5 #2857

Closed Jiyvn closed 4 months ago

Jiyvn commented 4 months ago

👓 What did you see?

Build success with no test executed with command mvn clean test

tv-ui-test-automation-gen1 % mvn clean test
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< groupId:VIU-AUTO-TV >-------------------------
[INFO] Building VIU-AUTO-TV 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ VIU-AUTO-TV ---
[INFO] Deleting /Users/jiyvn/IdeaProjs/tv-ui-test-automation-gen1/target
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ VIU-AUTO-TV ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ VIU-AUTO-TV ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 7 source files with javac [debug target 17] to target/classes
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ VIU-AUTO-TV ---
[INFO] Copying 5 resources from src/test/resources to target/test-classes
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ VIU-AUTO-TV ---
[INFO] Changes detected - recompiling the module! :dependency
[INFO] Compiling 5 source files with javac [debug target 17] to target/test-classes
[INFO] 
[INFO] --- surefire:3.1.2:test (default-test) @ VIU-AUTO-TV ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.069 s
[INFO] Finished at: 2024-03-06T16:29:55+08:00
[INFO] ------------------------------------------------------------------------

Runner (following https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit-platform-engine#suites-with-different-configurations).

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("tv/features") // src/test/resources/tv/features
@ConfigurationParameter(key = Constants.GLUE_PROPERTY_NAME, value = "tv.features") // src/test/java/tv/features
public class TVTestRunner {

    private static final Logger log = LoggerFactory.getLogger(TVTestRunner.class);

    @BeforeAll
    public void setUp() throws IOException {
        log.info("Runner ==> before all");
    }

}

Feature file

Feature: TV app onboarding
  As a user, I am able to log in on TV

  Scenario: Junit5 test with Apple TV
    When Launch Apple TV
    And Open Apps Dashboard
    And Open TestFlight

✅ What did you expect to see?

Run tests under src/test/resources/tv/features

📦 Which tool/library version are you using?

pom.xml

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <version>1.10.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.10.1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.10.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit-platform-engine</artifactId>
            <version>7.15.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite-engine</artifactId>
            <version>1.10.1</version>
            <scope>test</scope>
        </dependency>

📚 Any additional context?

@mpkorstanje could you or anyone help?

Jiyvn commented 4 months ago

sorry, I figured it out. I have to name the runner class normally with a suffix Test, which is different from Junit4.

mpkorstanje commented 4 months ago

It's the same with JUnit 4. Because it's not JUnit that does it. 😉

https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html