Reputation: 694
I'm trying to run simple Cucumber/Java test, via testng.xml.
So, I have testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Cucumber Framework">
<test name="Cucumber Tests" junit="true">
<classes>
<class name="CucumberFramework.runner.MainRunner"></class>
</classes>
</test>
</suite>
And I'm using runner.class in which I'm setting path/options/etc to featurefiles, steps, and reports:
package CucumberFramework.runner;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions (
features = {"src/test/java/CucumberFramework/featureFiles"},
glue = {"CucumberFramework.steps"},
monochrome = true,
tags = {},
plugin = {"pretty",
"html:target/cucumber",
"json:target/cucumber.json",
"com.cucumber.listener.ExtentCucumberFormatter:target/report.html"}
)
public class MainRunner extends AbstractTestNGCucumberTests {
}
But when I'm running my testng.xml as TestNG suite, it:
1) passing my scenarios themselves,
BUT
2) throwing "No tests were found".
What am I doing wrong?
Upvotes: 3
Views: 13280
Reputation: 169
I was facing similar issue when I was storing test data in a spreadsheet. I added on more column with Execute as Y and this was resolved.
Upvotes: -1
Reputation: 22993
A project with Cucumber and TestNG does not require a class with a method annotated with @Test
.
The No test were found
might be related to the way you run the Cucumber tests.
Find below a minimal project to show base requirements.
assuming following structure
src/test/java/stepdef/StepDefs.java
src/test/java/runner/RunnerTest.java
src/test/resources/features/test.feature
pom.xml
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.suboptimal</groupId>
<artifactId>cuke-testng3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>3.0.2</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
test.feature
Feature: test
Scenario: something to test
Given some step
Then this is expected
StepDefs.java
package stepdef;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
public class StepDefs {
@Given("^some step$")
public void someStep() throws Throwable {
System.out.println("execute someStep");
}
@Then("^this is expected$")
public void thisIsExpected() throws Throwable {
System.out.println("execute thisIsExpected");
}
}
RunnerTest.java
package runner;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(features = "src/test/resources/features", glue = "stepdef")
public class RunnerTest extends AbstractTestNGCucumberTests {
}
The test can be executed via Maven with
mvn clean test
output
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running runner.RunnerTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@5eb5c224
execute someStep
execute thisIsExpected
1 Scenarios (1 passed)
2 Steps (2 passed)
0m0.019s
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.552 sec
As the last line stated Test run: 1
the Cucumber scenario is recognized as a test run.
edit A possibility to execute the Cucumber tests as a TestNG suite.
add to the pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
create the file testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Cucumber Framework" >
<test name="Cucumber Tests">
<classes>
<class name="runner.RunnerTest"></class>
</classes>
</test>
</suite>
execute the test with Maven as
mvn clean test
output
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
execute someStep
execute thisIsExpected
1 Scenarios (1 passed)
2 Steps (2 passed)
0m0.020s
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.614 s - in TestSuite
Upvotes: 1
Reputation: 694
@SubOptimal - thanks man, for so clear explanation, now I know much more.
Regarding trouble itself - finally I resolved it just by deleting junit mentioning in testng.xml. As in description I noted "run as testng suite", I should mark this answer as correct, no offense.
Upvotes: 2