我将 IntelliJ 版本从 2017.3 升级到 2018.1,现在我无法再从 IDE 运行集成测试。
该项目是一个 Spring Boot 应用程序,使用 gradle 构建。集成测试基本上如下所示:
@RunWith(SpringRunner.class)
@SpringBootTest(
classes = TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE
)
@Transactional
public class MyServiceIT {
@Autowired
private MyService service;
@Test
public void test() {
// ...
}
}
仍然可以使用 gradle 运行测试,但无法从 IDE 运行隔离测试。
我收到此错误,因为实例无法再 Autowiring :
[INFO] org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [MyServiceIT]: no resource found for suffixes {-context.xml, Context.groovy}.
[INFO] org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
[INFO] org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@309e345f, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@56a6d5a6, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@18ce0030, org.springframework.test.context.support.DirtiesContextTestExecutionListener@4445629, org.springframework.test.context.transaction.TransactionalTestExecutionListener@45b9a632, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@25d250c6, org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener@4df50bcc, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@6b26e945, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@63a65a25, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@54c562f7, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@318ba8c8, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@6dbb137d, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@3c9d0b9d]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ...
我在 2017.1 版本上工作得很好。我想我必须更改 IDE 配置中的某些内容,但我不知道是什么。
我使用的是 Windows 10、IntelliJ 2018.1、Java 1.8 和 Spring Boot 1.5.10.RELEASE
最佳答案
最后,我让它再次运行。在运行/调试配置
中,工作目录
设置为$MODULE_DIR$
。在我的项目中,该问题没有正确解决。将工作目录
显式设置为项目根目录后,运行特定的集成测试就可以了。
关于spring-boot - IntelliJ 2018.1 Spring Boot 集成测试问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49728322/