Cucumber JUnit 5 mvn - 未找到测试

问题描述 投票:0回答:1

我在设置正确的测试生态系统时遇到问题。我正在关注其他项目,尽管他们使用 Gradle,这应该不会产生重大影响。 当我尝试将 Runner 与 JUnit 一起使用时,问题就出现了。每次,我都会得到“未找到测试”。我尝试过不同的路径,但没有帮助。在我看来,项目结构是正确的,代码应该能够毫无问题地到达步骤。

源代码 -主要的 -测试 -java -com.example -gui -StarterStep.java -TestRunner.java -资源 -特征 -测试1.功能 项目结构

StarterStep.java

public class StarterStep
{
    @Given("Start testing")
    public void openBrowser(){
        open("https://google.pl/");
    }
}

测试运行器

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = Constants.GLUE_PROPERTY_NAME, value = "com.example.gui")
@ConfigurationParameter(key = Constants.PLUGIN_PROPERTY_NAME,
        value = "pretty, summary, json:target/reports/cucumber-reports/cucumber.json,"
                + " io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm")
@ConfigurationParameter(key = Constants.FILTER_TAGS_PROPERTY_NAME, value = "@AM")
public class TestRunner
{

}

pom.xml

<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>org.example</groupId>
  <artifactId>JUnitTest</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <allure.version>2.27.0</allure.version>
    <cucumber.version>7.15.0</cucumber.version>
  </properties>
  <dependencies>
    <!-- JUnit 5 -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.10.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-suite-api</artifactId>
      <version>1.10.2</version>
      <scope>test</scope>
    </dependency>
    <!-- Cucumber -->
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>${cucumber.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit-platform-engine</artifactId>
      <version>${cucumber.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-picocontainer</artifactId>
      <version>${cucumber.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.codeborne</groupId>
      <artifactId>selenide-video-recorder</artifactId>
      <version>7.6.0</version>
      <scope>test</scope>
    </dependency>
    <!-- Allure -->
    <dependency>
      <groupId>io.qameta.allure</groupId>
      <artifactId>allure-selenide</artifactId>
      <version>${allure.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.qameta.allure</groupId>
      <artifactId>allure-cucumber7-jvm</artifactId>
      <version>${allure.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

我已经尝试过一一更改所有内容的版本。对 Cucumber 的测试是正确的,因为我可以从功能级别运行它。

java maven selenium-webdriver cucumber junit5
1个回答
0
投票

您正在使用

junit-platform-suite-api
。这只是执行
@Suite
注释的测试引擎的 API。您应该使用
junit-platform-suite
,它会传递性地添加对
-api
-engine
的依赖。

为了确保使用所有正确的版本,您需要对 JUnit 和 Cucumber 使用依赖关系管理。

所以一切都在一起

  <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.11.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>io.cucumber</groupId>
                <artifactId>cucumber-bom</artifactId>
                <version>7.20.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit-platform-engine</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-suite</artifactId>
            <scope>test</scope>
        </dependency>

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


... your other non-cucumber and non junit dependencies here 


    </dependencies>
© www.soinside.com 2019 - 2024. All rights reserved.