如何在集成测试中一起使用这些@DataMongoTest和@SpringBootTest

时间:2019-04-02 11:51:02

标签: junit integration-testing spring-boot-test

我正在尝试为我的其余应用程序之一(在内部使用mongodb持久存储数据)编写集成测试用例

@DataMongoTest 
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class MainControllerTest {
@LocalServerPort
    private int port = 8080;
/* some test cases*/ 
}

但是我遇到了错误

java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.sample.core.controller.MainControllerTest]: [@org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper)]

看起来这两个是互斥的,因此如何进行集成测试。

1 个答案:

答案 0 :(得分:0)

将@AutoConfigureDataMongo与@SpringBootTest一起使用,这将解决此歧义问题。 @SpringBootTest和@DataMongoTest不能一起使用。

相关问题