【问题标题】:Maven is ignoring Cucumber testsMaven 忽略 Cucumber 测试
【发布时间】:2021-07-14 13:31:18
【问题描述】:

我正在尝试通过 Maven 运行两个黄瓜功能文件,但没有任何反应。我正在使用荷兰语 (NL) 版本的 Gherkin。当我直接在 Eclipse 或 Gradle 中运行功能文件时,它们运行良好。我在 Stackoverflow 上研究了有关此问题的所有早期问题,但仍然找不到解决方案。

这是我在 Eclipse 中的项目结构: Eclipse project structure

使用 Maven 使用命令 mvn Test 运行项目的结果是:

Running nl.werkwel.cucumber.RunTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@f5c0729
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.341 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] BUILD SUCCESS

我也尝试过运行: “mvn 测试 -Dcucumber.options="src/test/resources/registratiepage.feature" 但结果是一样的

这是 POM

<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>nl.werkwel</groupId>
  <artifactId>cucumber</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>cucumber</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.4</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.8</version>

    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.4</version>
    </dependency>

  </dependencies>

</project>

这里是功能文件之一:

# language: nl
Functionaliteit: Testen van de Registratiepagina

  Achtergrond: 
      Gegeven Gebruiker is op de registratiepagina

  Scenario: Niet succesvolle registratie, emailadres niet gevuld
    Als Gebruiker geen emailadres invult
    En Klikt op de button nu registreren
    Dan wordt de melding "Voer een waarde in" getoond

    Scenario: Link Algeregistreerd
    Als Gebruiker op link algeregistreerd klikt
    Dan gaat gebruiker verder naar het inlogscherm

  Scenario: Link Annuleren
    Als Gebruiker op link annuleren klikt
    Dan gaat gebruiker verder naar het inlogscherm

跑者班

package nl.werkwel.cucumber;

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

@RunWith(Cucumber.class)
@CucumberOptions(


        plugin = {"pretty", "html:out"},
        features={"."}

        )


public class RunTest {

}

【问题讨论】:

  • 需要 POM 和至少一项功能。
  • 谢谢你的反应,我添加了信息。
  • 该功能文件的确切文件名是什么?另外,为什么你的 POM 中同时包含 JUnit 和 TestNG?
  • 我不知道TestNG,但是当使用JUnit(至少使用Java类)运行测试时,类的名称必须以'Test'结尾。所以也许你需要相应地命名你的测试文件。
  • 我删除了 JUnit 依赖项,将包含步骤定义的文件的名称更改为“LoginStepDefinitionsTest”。仍然没有运行测试。功能文件的名称是“registratiepage.feature”和“registrerengebruiker.feature”。

标签: java maven cucumber


【解决方案1】:

对于其他可能遇到我遇到的问题的人来说,@P.J.Meish 的回答对我有用:

“我不知道TestNG,但是当使用JUnit(至少使用Java类)运行测试时,类的名称必须以'Test'结尾。所以也许你需要相应地命名你的测试文件。”

所以我将我的测试运行器类重命名为以“测试”结尾,这解决了 maven 不运行我的黄瓜测试的问题。

【讨论】:

  • 就是这样,我错误地命名为FeatureTests,在这里我失去了理智。谢谢,就是这样,现在感觉很笨。
【解决方案2】:

是的,跑步者或主类名应该以 Test 结尾,

【讨论】:

  • 感谢您的回答,简单但很难找到我的代码中的错误!!!!!!!!!!!!
【解决方案3】:

maven 似乎没有找到任何测试。可以分享一下你的跑步课吗? 此外,您可能想定义 testng groupid 的范围。

https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesTest.java

编辑:

我今天学到了一些新东西……Given == gegeven!

我得到了您正在运行但有更改的项目。遵循项目的结构: https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng

以下是 pom 更改: 正如@chrylis 所质疑的那样,Junit 和 TestNG 都存在并且不需要。删除junit 您的依赖项将是这样的:

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.0</version>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>

    <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.4</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
  </dependencies>

我无法使套件与您的 Runner 类一起运行,并使用 TestNGCucumberRunner 类执行。

/** Create one test method that will be invoked by TestNG and invoke the 
 * Cucumber runner within that method.
 */
  @CucumberOptions(plugin = "json:target/cucumber-report-composite.json")
    public class RunCukesByCompositionTest {

    @Test(groups = "examples", description = "Example of using TestNGCucumberRunner to invoke Cucumber")
    public void runCukes() {
        new TestNGCucumberRunner(getClass()).runCukes();
    }
}

【讨论】:

  • 我添加了 Runner 类。我更改了 testng groupid 的范围以进行测试,但没有得到肯定的结果。
  • 看看这是否有帮助,@Frank
  • Thnx Sid,终于让我的测试运行起来了,不确定是项目结构、pom 还是 runner 类是失败的原因。我改变了他们三个人的事情。如果您有兴趣学习比“gegeven”更多的荷兰语,欢迎您
【解决方案4】:

实际上,我的 pom 文件中有黄瓜 junit 和 junit 依赖项。所以它导致了上述类似的问题。

我已将 runner 类更改为 runnerTest,然后从 pom 文件中删除了 junit 依赖项。

效果很好。试试这个..

谢谢,这里提供的其他解决方案对解决这个问题非常有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    • 2011-10-08
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    相关资源
    最近更新 更多