user1559625
user1559625

Reputation: 2673

Why running Cucumber test with Maven return result "Tests run: 0"?

I am using Maven in Eclipse to run Cucumber test. The project structure is as follows:

enter image description here

I used below Junit runner

@RunWith(Cucumber.class)
@CucumberOptions(
features={"src/test/resources/feature"}
,glue={"test.java.stepdefinition"}
)
public class CucumberJunitTest {
}

The test seems running fine. It's printing the correct log for scenario and steps.

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running test.java.cucumberjunit.CucumberJunitTest
a global administrator named
Successful Login with Valid Credentials: 1
Successful Login with Valid Credentials: 2
Successful Login with Valid Credentials: 3
Successful Login with Valid Credentials: 4

1 Scenarios ([32m1 passed[0m)
5 Steps ([32m5 passed[0m)
0m0.206s

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.85 sec - in test.java.cucumberjunit.CucumberJunitTest

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.794 s
[INFO] Finished at: 2015-11-26T22:52:07+11:00
[INFO] Final Memory: 14M/191M
[INFO] ------------------------------------------------------------------------

However, what bothers me is that it says Tests run: 0,???

I figured there must be something wrong. But what could be the reason?

BTW, just to verify, i tried to add another TestNG runner in the project:

@CucumberOptions(
features = {"src/test/resources/feature"}
,glue={"test.java.stepdefinition"}
)

public class CucumberTestNGPest extends AbstractTestNGCucumberTests{
}

and the TestNG runner is printing Tests run: 1 as expected.

Could anyone provide any thoughts? Many thanks.

UPDATE:

To clarify, CucumberJunitTest.java and CucumberTestNGTest.java (In attached screenshot CucumberTestNGTest.java name is changed to CucumberTestNGPest.java so that Surefire will not run it this time) are both Cucumber runners. I do not understand why JUnit test can not give the "Test run: 1" result, where TestNG test can.

Upvotes: 2

Views: 4983

Answers (2)

BlondCode
BlondCode

Reputation: 4159

You have testng and junit as well as dependencies. Try to use only junit so maven results won't be overwritten.

The minimal dependency list i needed in my pom afterall:

<properties>
    <properties>
    <junit.version>4.11</junit.version>
    <selenium.version>2.50.1</selenium.version>
    <cucumber.version>1.2.0</cucumber.version>
</properties>


<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Upvotes: 2

N..
N..

Reputation: 956

I think one this missing and it is result plugin. I think this can fix issue.

@CucumberOptions(plugin = { "pretty","json:target/stepdefinition.json" }
features = {"src/test/resources/feature"}
,glue={"test.java.stepdefinition"}
)

public class CucumberTestNGPest extends AbstractTestNGCucumberTests{
}

Upvotes: 0

Related Questions