已生成Maven项目 cucumber 测试,但结果为0

0g0grzrc  于 2022-09-20  发布在  Maven
关注(0)|答案(1)|浏览(207)

当我在终端mvn test -Dcucumberoptions="--tags @Smoke中使用此命令时,我的测试结果始终为0。以下是我的POM、测试运行器和功能类;
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>

cucumber 选项的TestRunner类

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文件

@Smoke
  Scenario: 5SH Share Privately

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

最后是我的结果

[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] ------------------------------------------------------------------------

暂时感谢您的建议

kknvjkwl

kknvjkwl1#

Sure Fire通常会根据项目类路径中存在的TestNG/JUnit版本自动选择要使用的测试框架提供程序。

您的类路径上同时有JUnit5和JUnit4,因此Sure Fire将选择JUnit5来运行所有测试。但是,您没有包括JUnit Vintage engine,因此JUnit5将不会执行JUnit4测试。

不过,您最好完全切换到JUnit5。看看cucumber-java-skeleton就可以了。

相关问题