Home > Mobile >  Maven project cucumber test builded but result is 0
Maven project cucumber test builded but result is 0

Time:09-16

When i use this command in terminal mvn test -Dcucumberoptions="--tags @Smoke my test result is 0 all the time. Here is my pom, test runner and feature classes;

pom.xml

<properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <aspectj.version>1.8.10</aspectj.version>
    </properties>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>4.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>4.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0-rc-2</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.5.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.5.0</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <version>2.2</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-junit5 -->
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-junit5</artifactId>
            <version>2.13.6</version>
        </dependency>


        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160212</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>4.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.9.0</version>
            <scope>test</scope>
        </dependency>



    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <includes>
                        **/TestRunner*.java
                    </includes>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

TestRunner class for cucumber options

package cucumberOptions;



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

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features",
        glue = {"Steps"}
)

public class TestRunner {

}

.feature file

@Smoke
  Scenario: 5SH Share Privately

    When I send share privately api
    Then response share status code should be 201

And last my result

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< Automation:Automation >-----------------
[INFO] Building LifeboxAutomation 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Automation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 7 resources
[INFO] Finished at: 2022-09-15T13:08:38 03:00
[INFO] ------------------------------------------------------------------------
 mtc   BackendApi  mvn test -Dcucumberoptions="--tags @Smoke"                                                                                                            in pwsh at 13:08:38 
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------< Automation:LifeboxAutomation >-----------------
[INFO] Building Automation 1.0-SNAPSHOT                                 
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Automation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 7 resources
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Automation ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Automation ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Automation ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ Automation ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.056 s
[INFO] Finished at: 2022-09-15T13:20:17 03:00
[INFO] ------------------------------------------------------------------------

Thank you for your advice for now

CodePudding user response:

Surefire normally automatically selects which test-framework provider to use based on the version of TestNG/JUnit present in your project's classpath.

You have both JUnit 5 and JUnit 4 on your classpath, so Surefire will pick JUnit 5 to run all tests. However you didn't include the JUnit Vintage engine so JUnit 5 will not execute JUnit 4 tests.

You're probably better of switching to JUnit 5 entirely though. Have a look at the cucumber-java-skeleton for that.

  • Related