【发布时间】:2017-12-21 23:33:03
【问题描述】:
我有一个
@AutoConfigureMockMvc
@SpringBootTest(classes=[AppConfigTest])
@AcitveProfile("unittest")
ControllerTest
其中
@TestConfiguration
@Profile("unittest")
AppConfigTest
并且位于/src/test 包下。 AppConfigTest 有 bean 来覆盖 AppConfig 中定义的 bean。 ControllerTest 运行得很好,在 AppConfigTest 而不是 AppConfig 中选择 bean。
现在,我创建
@Configuration
@Profile(["local", "unittest"])
AppConfigLocal
位于/src/main 下,如果我将 ControllerTest 更改为
@SpringBootTest(classes = [AppConfigLocal])
@ActiveProfile("unittest")
ControllerTest
现在我的 ControllerTest 似乎不再选择控制器了(测试失败,“没有找到带有 URI 的 HTTP 请求的映射...”
但它并没有真正说明为什么控制器没有连接到 mockmvc...
【问题讨论】:
标签: spring unit-testing spring-boot spring-profiles