gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:20:54 25 4
gpt4 key购买 nike

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

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

最佳答案

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

关于junit - 如何在集成测试中一起使用这些@DataMongoTest 和@SpringBootTest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55474104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com