Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven is ignoring Cucumber tests

I'm trying to run two cucumber feature files by Maven but nothing happens. I'm using the Dutch (NL) version of Gherkin. When I'm running the feature files directly in Eclipse or with Gradle they are running fine. I studied all earlier questions about this issue on Stackoverflow but still couldn't find a solution.

This is my project structure in Eclipse: Eclipse project structure

The result of running the project with Maven using the command mvn Test is:

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

This is the 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 {

}
like image 664
Frank Avatar asked Sep 25 '16 14:09

Frank


4 Answers

For anyone else coming to this question that may have had the issue I was having, @P.J.Meish's answer worked for me:

"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."

So I renamed my test runner class to end with 'Test' and that resolved the issue of maven not running my cucumber tests.

like image 150
sushimama Avatar answered Oct 27 '22 01:10

sushimama


Yup the runner or main class name should end with Test,

like image 41
greyProgrammer Avatar answered Oct 26 '22 23:10

greyProgrammer


It seems like maven didnt find any tests. Can you share your runner class? Also, you may wanna define the scope for your testng groupid.

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!

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

Here are the pom changes: As @chrylis had questioned, Junit and TestNG were both present and is not needed. Delete junit Your dependencies would be something like this:

<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.

/** 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();
    }
}

enter image description here

like image 20
Sid Avatar answered Oct 26 '22 23:10

Sid


Actually i had the cucumber junit and junit dependency in my pom file. 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.

it worked well. try this ..

Thanks , Other solutions are provided here is very useful to figure this things.

like image 44
sathi raj Avatar answered Oct 27 '22 00:10

sathi raj