在测试中无法识别应用程序配置。 build.gradle的依赖关系
springBootVersion = '1.3.3.RELEASE'
testCompile('org.springframework.boot:spring-boot-starter-test',
"info.cukes:cucumber-jvm:1.2.4",
"info.cukes:cucumber-core:1.2.4",
"info.cukes:cucumber-java:1.2.4",
"info.cukes:cucumber-junit:1.2.4",
"info.cukes:cucumber-spring:1.2.4",
'commons-io:commons-io:2.4')
CukeOptions
@RunWith(Cucumber.class)
@CucumberOptions(
format = { "pretty", "html:target/cucumber" },
features = "src/test/resources/features",
dryRun = false
)
public class CukeOptions{
}
cucumberMain.java
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@ContextConfiguration(classes = IngestBatchApplication.class, loader = SpringApplicationContextLoader.class)
@WebAppConfiguration
@IntegrationTest
public class CucumberMain {
public static void main(String args[]) {
JUnitCore jUnitCore = new JUnitCore();
jUnitCore.run(CukeOptions.class);
}
}
这是我的stepDefs
public class stepDefs {
@Autowired
private ApplicationContext context;
@When("^And get user details$")
public void get_user_details() throws Throwable {
// Unable to get user details from bean
}
}
ApplicationContext返回NULL
答案 0 :(得分:0)
试试这个:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@ContextConfiguration(classes = IngestBatchApplication.class, loader = SpringApplicationContextLoader.class)
@WebAppConfiguration
@IntegrationTest
public class stepDefs {
@Autowired
private ApplicationContext context;
@When("^And get user details$")
public void get_user_details() throws Throwable {
// Unable to get user details from bean
}
}