spring-boot - IntelliJ 2018.1 Spring Boot 集成测试问题

标签 spring-boot intellij-idea

我将 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/

相关文章:

java - Intellij 为方法和类生成 javadoc

eclipse - IDE 中的 Thymeleaf 支持

java - 无法使用 Spring Data JPA 搜索对象的嵌套列表

java - 我应该如何获取 javafx spring boot 桌面应用程序的 OAuth2 访问 token ?

maven - 将基于Vaadin 11的Maven驱动项目改成Vaadin 12 alpha版本?

java - 我尝试在我的 rpi 上使用 jdk.dio 并得到 'no dio in java.library.path'

java - 在 Intellij IDEA 中创建基于 Gradle 的 Web 应用程序

java - 新端点在测试中导致 IllegalStateException : Invalid mime type "headers": does not contain '/'

java - 如何为 DirectoryStream 编写 junit 测试

java - 如果我们试图将 JSON 放入 hashmap 中,我们如何使用 jackson 处理 JSON 内部的 JSON?