Reputation: 55
I have a cucumber project. When I right click on the RunnerTest class and "Run "RunnerTest" all the features from the feature file starts running. All tests pass.
My RunnerTest.class
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import java.sql.SQLException;
import lombok.extern.log4j.Log4j2;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"classpath:foo.feature"},
glue = "com.foo.foobar.StepDefinitions",
plugin = {"json:target/cucumber-report/cucumber.json"},
monochrome = true,
strict = true
//,dryRun = true
)
@Log4j2
public class RunnerTest {}
But when I try to run mvn test or mvn clean install features are not running. This is the output.
Running TestSuite Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@515f550a Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.895 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
These are my POM dependencies
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>3.0.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>4.1.3</version>
</dependency>
<!--<dependency>-->
<!--<groupId>junit</groupId>-->
<!--<artifactId>junit</artifactId>-->
<!--<version>4.12</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>test</scope>
</dependency>
I have tried to add mvn surefire plugin and including my RunnerTest Class there.
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>RunnerTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
But that does not work either
Upvotes: 3
Views: 7361
Reputation: 1996
Known Issue : If you keep Junit & TestNG both dependencies in parallel, Then TestNG dependency causes Surefire to ignore JUnit wrapper class.
Solution : There could be multiple way of handling this like we can define 2 execution, each for TestNG & JUnit and disable one as per your need.
Can you please try with this : Please remove any direct/indirect TestNG dependency.
org.testng testng 6.14.3 test
And try to add below one -
io.cucumber cucumber-testng 3.0.0
Also, I would suggest you one more thing to keep your pom.xml clean.
Key Point :
You shall remove cucumber-core, cucumber-java, cucumber-jvm, cucumber-jvm-deps, gherkin as these are transitive dependencies which would get added by Maven when you add below direct (main) dependencies. Just add below 2 and one for testng shared above.
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>3.0.0</version>
</dependency>
Upvotes: 4