如何在集成测试中将这些@DataMongoTest和@SpringBootTest结合使用 [英] How to use these @DataMongoTest and @SpringBootTest together in integration test

查看:29
本文介绍了如何在集成测试中将这些@DataMongoTest和@SpringBootTest结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的一个睡觉应用程序编写集成测试用例,该应用程序在内部使用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不能一起使用。

这篇关于如何在集成测试中将这些@DataMongoTest和@SpringBootTest结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆