Wojciech
Wojciech

Reputation: 81

no "Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, " even that cucumber test was executed using "mvn test" command

Could someone suggest me a solution why when I run the test using command mvn test to run the cucumber runner class ExampleRunnerTest located in \src\test\java it runs but the maven build doesn't recognize it. Like I said the test runs does what it should do but the build still fails.

1 Scenarios (←[32m1 passed←[0m)
6 Steps (←[32m6 passed←[0m)
1m36.764s

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 98.777 sec - in BasicTest

Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/main/java/cucumber/feature/Basic.feature", glue = "cucumber/stepDefinition",
    format = {"pretty", "html:target/cucumber", "json:target/cucumber-report.json"})

public class BasicTest {
}

Upvotes: 6

Views: 28325

Answers (5)

Yasin Bekar
Yasin Bekar

Reputation: 147

@Rai Gupta is right. The dependency was an issue for me also. I saw too many Append your runner class with Test, move the runner class into TEST folder

But you are just destroying the whole design and it will end with a differently designed framework.

JUnit and SureFire plugin need to be aligned. I used

    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13.1</version>
        <scope>test</scope>
    </dependency>

And the plugin

    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.4</version>

However, this produced a parallel execution problem. I did not need it, I removed it eventually. But you can try different versions of the above dependency.

Lastly, this Stack Overflow thread worked for me Tests not running through Maven?

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-engine</artifactId>
  <version>5.3.2</version>
</dependency>

Upvotes: 4

Manoel Campos
Manoel Campos

Reputation: 1001

I fixed this issue with JUnit 5 by explicitly adding the following plugins in their latest versions:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.1.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.1.2</version>
            </plugin>
        </plugins>
    </build>

Version 2.x doesn't work.

Upvotes: 1

Cjo
Cjo

Reputation: 1351

This could be issue with jUnit supprt in surefire lib. I followed this link to fix the issue.
It works ! Why Your JUnit 5 Tests Are Not Running Under Maven

Upvotes: 0

BlondCode
BlondCode

Reputation: 4159

When I had this problem in my Selenium project I realized that I was using junit and TestNG as well. I removed TestNG codes and dependency from pom.xml. This way I only had junit in my project left. Then everything worked like charm, MVN test results showed the correct numbers.

Upvotes: 4

user13745269
user13745269

Reputation: 11

This is what I did for it to work for me

  1. Like user = BlondCode said remover or comment TestNG dependency from you pom.xml file.

  2. Add JUnit vintage engine dependency to pom.xml

  3. Add a resources folder where you will store your feature and step definitions packages e.g. = \src\test\java\resources\feature and \src\test\java\resources\step definitions

  4. You runner package remains in \src\test\java folder

  5. Last but not the least add the below configuration to surefire plugging. See image below

enter image description here

Upvotes: 1

Related Questions