我正在尝试为我的其余应用程序之一编写集成测试用例,该应用程序在内部使用 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 不能一起使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)