如何在一个MVC应用程序中结合使用@DataJpaTest @SpringBootTest来测试每一层? [英] How can I combine @DataJpaTest @SpringBootTest in one MVC application for testing every layer?

查看:116
本文介绍了如何在一个MVC应用程序中结合使用@DataJpaTest @SpringBootTest来测试每一层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里 https://stackoverflow.com/a/52968130/10894456 很好地解释了为什么@DataJpaTest @SpringBootTest应该不能混用在一个应用程序中.

Here https://stackoverflow.com/a/52968130/10894456 is well explained why @DataJpaTest @SpringBootTest shouldn't be mixed in one application.

但是几乎没有解释何时仍然需要测试MVC SpringBoot应用程序的每一层的情况(从我的角度出发,不仅测试一层或只有另一层,而且测试两层乃至所有层是很自然的,不是吗?)

But barely explained the case when anyway need to test every layer of MVC SpringBoot application (from my point it's natural to test not only one or only another layer but both and even all layers, isn't it?)

因此,有人建议使用@AutoConfigureTestDatabase而不是@DataJpaTest的解决方案,但未完成工作((((

So there was suggested a solution to use @AutoConfigureTestDatabase rather than @DataJpaTest but didn't finish the job (((

所以我的问题是:使用@AutoConfigureTestDatabase是合适的解决方案吗?如果是,请说明详细信息.如果否,请提出更合适的解决方案,谢谢

So my question is: is using @AutoConfigureTestDatabase an appropriate solution? If yes, please explain details. If no, please suggest more appropriate solution, thank you

推荐答案

假设您想要完整的应用程序,但数据库不在内存中,是的,将@SpringBootTest与@AutoConfigureTestDatabase结合使用是一个合适的解决方案,因为它确实可以那个.

Assuming you want the full application with the exception of database being in-memory, yes, combining @SpringBootTest with @AutoConfigureTestDatabase is an appropriate solution, as it does just that.

还提到 :

如果您希望加载完整的应用程序配置,但使用嵌入式数据库,则应考虑将@SpringBootTest与@AutoConfigureTestDatabase结合使用,而不是此注释.

If you are looking to load your full application configuration, but use an embedded database, you should consider @SpringBootTest combined with @AutoConfigureTestDatabase rather than this annotation.

这篇关于如何在一个MVC应用程序中结合使用@DataJpaTest @SpringBootTest来测试每一层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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