I am using Cucumber to automate the testing of services and controllers in my app. In addition, I am using the Cucumber Junit runner @RunWith(Cucumber.class)
in the
I just made cucumber and spring working with java based configuration and I think it is worth to share here. here what I have done:
@Configuration
@ComponentScan(basePackages = { "com.*" })
@PropertySource("classpath:application-${environment}.properties")
public class AppConfiguration {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
my step defintion class:
@ContextConfiguration(classes= AppConfiguration.class)
public class Stepdefs {
@Autowired
private MyBean mybean;
and here the test class:
@RunWith(Cucumber.class)
@CucumberOptions(format = { "pretty", "html:target/cucumber-html-report", "json:target/cucumber-json-report.json" })
@ContextConfiguration(classes= AppConfiguration.class)
public class RunCucumberTest {
}
and the maven command is:
mvn -Denvironment=dev clean test
the maven dependencies I have in my pom are:
org.springframework
spring-expression
${org.springframework.version}
org.springframework
spring-beans
${org.springframework.version}
org.springframework
spring-aop
${org.springframework.version}
org.springframework
spring-context
${org.springframework.version}
org.springframework
spring-context-support
${org.springframework.version}
org.springframework
spring-test
${org.springframework.version}
junit
junit
${junit.version}
test
org.hamcrest
hamcrest-library
${hamcrest.version}
test
info.cukes
cucumber-java
${cucumber.version}
test
info.cukes
cucumber-spring
${cucumber.version}
test
info.cukes
cucumber-junit
${cucumber.version}
test
info.cukes
cucumber-jvm
${cucumber.version}
pom