问题描述
这里 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.
这篇关于如何在一个MVC应用程序中结合使用@DataJpaTest @SpringBootTest来测试每一层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!