简体   繁体   中英

Cucumber JUnit platform engine. Console failure

I've recently started working with Cucumber JUnit platform engine. Everything is fine, code is running, however, problem arrises while I am trying to run code via console (mvn clean install -Dtest=CucumberTest).

Test run via intelliJ:

在此处输入图像描述

Test run via console:

From the log perspective in console, I see, that tests were executed, however, in summary I am getting "No tests were executed error". What are the reason behind this issue? Thanks, guys

   [INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[ERROR] Apr 28, 2021 2:58:55 PM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
[ERROR] INFO: Loading JUnit Platform configuration parameters from classpath resource [/***/IdeaProjects/cucumber-testing/target/classes/junit-platform.properties].

@ab
Scenario: Scenario21           # steps/suite2.feature:4

@isolated @ab @ac
Scenario: Scenario12           # steps/suite1.feature:9

@isolated @ab @gc
Scenario: Scenario11           # steps/suite1.feature:5

@ab
Scenario: Scenario22           # steps/suite2.feature:8
  When Wait for amount of time # steps.TestSteps.waitFor()
  When Wait for amount of time # steps.TestSteps.waitFor()
  When Wait for amount of time # steps.TestSteps.waitFor()
  When Wait for amount of time # steps.TestSteps.waitFor()
ForkJoinPool-1-worker-5
ForkJoinPool-1-worker-4
ForkJoinPool-1-worker-1
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
ForkJoinPool-1-worker-2
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.051 s
[INFO] Finished at: 2021-04-28T14:58:57+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project cucumber: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Process finished with exit code 1

My pom.xml file looks like this:

<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>ii.Testing</groupId>
    <artifactId>cucumber</artifactId>
    <version>1.0.0</version>

    <properties>
        <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
        <cucumber.version>6.10.3</cucumber.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit-platform-engine</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
            </plugin>
        </plugins>
    </build>
</project>

It seems IntelliJ is using the Junit4 way of using Cucumber contrary to Maven which is using the Junit5 way. If you want to use the Junit4 way you need to remove cucumber-junit-platform-engine from your dependencies.

To use Cucumber with Junit5, it's not out of the box and it's not well documented.

First you need to remove the dependency cucumber-junit :

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

Because it's related to the Junit4 way of using Cucumber .

You already have the dependency for Cucumber with Junit5 :

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit-platform-engine</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

In your code you need to replace the use of:

@RunWith(Cucumber.class)
@CucumberOptions(...)

By io.cucumber.junit.platform.engine.Cucumber from cucumber-junit-platform-engine:

@Cucumber

The last trick to make it Junit5 compliant is to move the feature files under the same repository structure as the package annoyed by @Cucumber meaning ii.Testing.cucumber.CucumberIT annoted by @Cucumber needs to have the feature files under the following folder structure:

  • ii\testing\cucumber

With all *.feature in it or in subfolder under it.

The last thing is to have cucumber properties working and the only way I managed to make it work with Junit5 is by using junit-platform.properties and add directly the property.

By example:

cucumber.publish.quiet=true
cucumber.plugin=pretty, summary, html:target/cucumber/report.html,json:target/cucumber/cucumber.json,junit:target/cucumber/cucumber.xml
cucumber.filter.tags=not @not-implemented and not @manual and not @unit-test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM