【发布时间】:2017-01-09 09:28:00
【问题描述】:
我的项目分为几个 gradle 子项目(模块)。我有一个包含几个弹簧组件/bean 的模块。我想使用 junit、mockito 和 springboottest 测试这些 bean,这些 bean 具有 autowired 和 mockbean 等功能。我正在使用
@RunWith(SpringJUnit4ClassRunner::class)
@SpringBootTest
注释,但是当我尝试运行测试时,我得到了
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
这是因为该模块中没有主类(@SpringBootApplication)。
可以通过创建类似的模拟主类来避免这种情况
@SpringBootApplication
class TestApp {
}
有没有办法让它在不创建模拟主类的情况下工作?
【问题讨论】:
标签: spring unit-testing testing spring-boot