Similar to this older post I have a Java application using Spring boot and Cucumber.
This application's purpose is to use Selenium to validate some tools my team uses, so my tests are all in the main scope.
The tests run fine in the IDE, but when I package my jar and try running it, I get No backends were found. Please make sure you have a backend module on your CLASSPATH.
After some searching, I configured the spring-boot-maven-plugin to unpack the cucumber-java dependency. That fixed the "no backend" error, but now, when I run the jar, I get my feature files printed on the console but no tests really execute (It goes by too fast, and I even introduced an error but it finished successfully anyways.
My pom:
<properties>
<cucumber.version>4.7.1</cucumber.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<requiresUnpack>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
</dependency>
</requiresUnpack>
</configuration>
</plugin>
</plugins>
</build>
My main class:
@SpringBootApplication
public class ExecutableMain implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ExecutableMain.class, args);
}
@Override
public void run(String... args) {
for (String arg : args) {
...
}
Result result = JUnitCore.runClasses(Test1.class, Test2.class, Test3.class);
if (result.wasSuccessful()) {
System.out.println("Success!");
} else {
System.out.println("Failure!");
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
}
}
}
One of the tests?
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty", "html:target/cucumber-test1", "json:target/cucumber-test1/cucumber.json"},
glue = {"cucumber.test1", "cucumber.steps"},
features = "src/main/resources/cucumber/test1/"
)
public class Test1 {
}
Console result:
INFO 15724 --- [ main] cucumber.ExecutableMain : Starting ExecutableMain
INFO 15724 --- [ main] cucumber.ExecutableMain : No active profile set, falling back to default profiles: default
INFO 15724 --- [ main] cucumber.ExecutableMain : Started ExecutableMain in 4.546 seconds (JVM running for 8.234)
INFO 15724 --- [ main] c.runtime.java.ObjectFactoryLoader : Loading ObjectFactory via service loader: io.cucumber.spring.SpringFactory
Feature: my test feature
Validates stuff
Scenario: my test scenario
Given foo
Then Bar
...
Success!