I am writing a new app and trying to do BDD using cucumber and Spring Boot 1.4. Working code is as shown below:
@SpringBootApplication
public class Application {
I've got it working in Spring Boot 1.5. I want to share the configuration with you:
org.springframework.boot
spring-boot-starter-parent
1.5.7.RELEASE
...
...
info.cukes
cucumber-java
1.2.5
test
info.cukes
cucumber-spring
1.2.5
test
info.cukes
cucumber-junit
1.2.5
test
...
Feature: User should be greeted
Background:
Given The database is empty
Then All connections are set
Scenario: Default user is greeted
Given A default user
When The application is started
Then The user should be greeted with "Hello Marc!"
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources", strict = true)
public class CucumberTests { // Classname should end on *Tests
}
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ContextConfiguration
abstract class AbstractSpringConfigurationTest {
}
class CucumberGlue : AbstractSpringConfigurationTest() {
@Autowired
lateinit var restTemplate: TestRestTemplate
@Autowired
lateinit var restController: RestController
@Autowired
lateinit var personRepository: PersonRepository
@Autowired
lateinit var entityManager: EntityManager
private var result: String? = null
@Given("^The database is empty$")
fun the_database_is_empty() {
personRepository.deleteAll()
}
@Then("^All connections are set$")
fun all_connections_are_set() {
assertThat(restTemplate).isNotNull()
assertThat(entityManager).isNotNull()
}
@Given("^A default user$")
fun a_default_user() {
}
@When("^The application is started$")
fun the_application_is_started() {
result = restController.testGet()
}
@Then("^The user should be greeted with \"([^\"]*)\"$")
fun the_user_should_be_greeted_with(expectedName: String) {
assertThat(result).isEqualTo(expectedName)
}
}