Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber Test a Spring Boot Application

Tags:

Does anyone know where I can find a sample application where Cucumber is used to test a Spring Boot application through Gradle? I can run the tests fine starting the server on the cmd line and using my IDE, but I need to be able to run them all programmatically on the CI server. I saw the answer on here but that solution did not work for me, most likely because I have multiple step def files.

Here is my setup

build.grade (Mentioned in the other question)

testCompile ("org.springframework.boot:spring-boot-starter-test",     ...     "info.cukes:cucumber-spring:${cucumberVersion}") 

CucumberTest.java

@RunWith(Cucumber.class) @CucumberOptions(format = "pretty", features = "src/test/resources") public class CucumberTest{ } 

AbstractSpringTest.java (Extended by all the StepDef files)

@SpringApplicationConfiguration(classes = Application.class) @RunWith(SpringJUnit4ClassRunner.class) @Ignore public abstract class AbstractSpringTest { ... } 

It's not doing the correct thing on start up because its 1. trying to initialize my step def files and 2. My application is not started and the cucumber tests cannot make a connection.

Thanks.

EDIT: Or if someone can tell me how to start and stop the application using gradle, that would be acceptable as well.

like image 766
jakehschwartz Avatar asked Jun 05 '15 13:06

jakehschwartz


Video Answer


1 Answers

I have solved the issue with some help from this question.

Here is the repository with the answer: https://github.com/jakehschwartz/spring-boot-cucumber-example

In short, the AbstractSpringTest class needs to have the following annotations:

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = DemoApplication.class, loader = SpringApplicationContextLoader.class) @WebAppConfiguration @IntegrationTest 
like image 139
jakehschwartz Avatar answered Sep 21 '22 00:09

jakehschwartz