简体   繁体   English

Maven 忽略了 Cucumber 测试

[英]Maven is ignoring Cucumber tests

I'm trying to run two cucumber feature files by Maven but nothing happens.我正在尝试通过 Maven 运行两个黄瓜功能文件,但没有任何反应。 I'm using the Dutch (NL) version of Gherkin.我正在使用荷兰语 (NL) 版本的小黄瓜。 When I'm running the feature files directly in Eclipse or with Gradle they are running fine.当我直接在 Eclipse 或 Gradle 中运行功能文件时,它们运行良好。 I studied all earlier questions about this issue on Stackoverflow but still couldn't find a solution.我在 Stackoverflow 上研究了有关此问题的所有早期问题,但仍然找不到解决方案。

This is my project structure in Eclipse: Eclipse project structure这是我在Eclipse 中的项目结构Eclipse project structure

The result of running the project with Maven using the command mvn Test is:使用命令 mvn Test 使用 Maven 运行项目的结果是:

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

I also tried to run with: "mvn test -Dcucumber.options="src/test/resources/registratiepage.feature" but the result was the same我也尝试运行:“mvn test -Dcucumber.options="src/test/resources/registratiepage.feature”但结果是一样的

This is the POM这是 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>

And here is one of the feature files:这是功能文件之一:

# 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

The Runner Class跑者班

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 {

}

For anyone else coming to this question that may have had the issue I was having, @PJMeish's answer worked for me: 对于那些可能遇到过这个问题的人来说,@ PJMeish的回答对我有用:

"I don't know about TestNG, but when running test with JUnit (at least with Java classes), the names of the classes must end with 'Test'. So maybe you need to name your testfile accordingly." “我不知道TestNG,但是当用JUnit运行测试时(至少使用Java类),类的名称必须以'Test'结尾。所以也许你需要相应地命名你的测试文件。”

So I renamed my test runner class to end with 'Test' and that resolved the issue of maven not running my cucumber tests. 所以我将我的测试运行器类重命名为'Test'结束,这解决了maven没有运行我的黄瓜测试的问题。

Yup跑步者或主要类名应该以Test结尾,

It seems like maven didnt find any tests. 似乎maven没有找到任何测试。 Can you share your runner class? 你能分享一下你的跑步者课吗? Also, you may wanna define the scope for your testng groupid. 此外,您可能想要定义testng groupid的范围。

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

Edit: 编辑:

I learnt something new today ... Given == gegeven! 我今天学到了一些东西......鉴于= = gegeven!

I got the project you have running but with changes. 我得到了你运行的项目,但有变化。 Follow the structure for the project: https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng 遵循项目的结构: https//github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng

Here are the pom changes: As @chrylis had questioned, Junit and TestNG were both present and is not needed. 以下是pom的变化:正如@chrylis所质疑的那样,Junit和TestNG都在场并且不需要。 Delete junit Your dependencies would be something like this: 删除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>

I was not able to make the suite run with your Runner class and used TestNGCucumberRunner class for execution. 我无法使用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();
    }
}

在此输入图像描述

Actually i had the cucumber junit and junit dependency in my pom file.实际上,我的 pom 文件中有黄瓜 junit 和 junit 依赖项。 So its causing the similar issue as mentioned.所以它导致了上述类似的问题。

I have changed the runner class to runnerTest and then removed the junit dependency from the pom file.我已将 runner 类更改为 runnerTest,然后从 pom 文件中删除了 junit 依赖项。

it worked well.它运作良好。 try this ..尝试这个 ..

Thanks , Other solutions are provided here is very useful to figure this things.谢谢,这里提供的其他解决方案对于解决这个问题非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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