小编F.d*_*doe的帖子

Java - Spring boot - 集成测试 - TestEntityManager 没有被注入

我有一个集成测试来测试我的 Spring Boot 服务器的 REST 端点。

我需要创建一些数据(不使用 REST 端点),所以我尝试使用 TestEntityManager,所以我用 @SpringBootTest 注释了我的测试类。到目前为止一切顺利,测试启动了 spring 引导上下文,所以我的服务器,测试通过了。

问题:我需要在此集成测试之外启动我的 Spring Boot 服务器,以便为所有集成测试运行一个实例(而不是每个测试中的新实例)。为此,我在预集成测试中使用 spring-boot-maven-plugin 启动服务器。到目前为止一切顺利,它开始了。但是,为了防止我的集成测试启动它自己的 Spring Boot 服务器,我需要从我的 IT 类中删除 @SpringBootTest 注释。
然后问题就来了。即使使用 @AutoConfigureTestEntityManager 注释,我的 TestEntityManager 也不会再被注入。

任何的想法 ?非常感谢

2017-03-14 10:42:31,371 ERROR o.s.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@56bf6f1e] to prepare test instance [be.mycompany.controllers.mediaRestControllerIT@340ef431]
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    ....
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testEntityManager' defined in class path resource [org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManagerAutoConfiguration.class]: Unsatisfied dependency expressed through method …
Run Code Online (Sandbox Code Playgroud)

java integration-testing spring-boot

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

integration-testing ×1

java ×1

spring-boot ×1