【问题标题】:How to use these @DataMongoTest and @SpringBootTest together in integration test如何在集成测试中一起使用这些 @DataMongoTest 和 @SpringBootTest
【发布时间】:2019-08-23 17:45:38
【问题描述】:

我正在尝试为我的其余应用程序之一编写集成测试用例,该应用程序在内部使用 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)]

看起来这两者是互斥的,那么如何进行集成测试。

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-06-22
    • 2021-04-12
    • 2019-03-12
    • 2019-11-07
    • 2014-05-06
    • 2017-07-24
    • 2023-04-05
    • 2013-09-23
    • 1970-01-01
    相关资源
    最近更新 更多