如何在集成测试中一起使用这些@DataMongoTest 和@SpringBootTest
How to use these @DataMongoTest and @SpringBootTest together in integration 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)]
看起来这两个是互斥的,那么如何进行集成测试。
将@AutoConfigureDataMongo 与@SpringBootTest 一起使用,这将解决此歧义问题。 @SpringBootTest 和@DataMongoTest 不能一起使用。
我正在尝试为我的其余应用程序之一编写集成测试用例,该应用程序在内部使用 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 不能一起使用。