英文:
Java test project for integration tests
问题
我必须与一些旧的Java应用程序一起工作。
总共有6个项目,它们:
- 通过REST和MQ进行通信,并且
- 已经具有一些集成测试。
作为其中的一部分:
- 初始请求使用mvcMock进行模拟测试
- 由服务发出附加的HTTP请求,并且
- 它们针对开发服务器进行,而不是调用当前构建的代码;
- 如果我的测试使用与开发人员尚未拥有的新端点与另一个项目进行通信的代码,它将失败。
我如何考虑测试这个问题
我的想法是使用单个测试项目,该项目将使用@SpringBootTest运行所有所需的项目,并使用mockmvc来模拟真实调用,并将它们转移到测试中,而不是使用真实端点。
要求
- 我不明白如何使Spring使用@Autowired并运行6个不同的WebApplicationContext。
- 或者也许我应该放弃我的计划,使用不同的东西。
英文:
I have to work with some old java application.
There is a total of 6 projects which:
- communicate using rest and mq and
- already have some integration tests.
As part of this:
- mvcMock mocks are used for the initial requests from test
- additional http requests are made by services and
- they go against dev server instead of calling code from current build;
- it'll fail if my test use code which communicates with another project by new endpoint which dev do not have yet.
How I thought of testing this
My idea was to use single test project which will run all required projects using @SpringBootTest and mockmvc to mock real calls and transfer them inside test instead of using real endpoints.
The ask
- I don't get how to make Spring to work with @Autowired and run 6
different WebApplicationContext's. - Or maybe i should forget my plan and use something different.
答案1
得分: 1
关于 @SpringBootTest
,它应该加载所有必要的内容,以加载单个Spring Boot驱动的应用程序。
因此,Spring Boot测试文档中提到的 "集成测试" 是指针对一个特定应用程序的。
现在,你正在谈论已经存在的6个应用程序。如果这些应用程序都是Spring Boot驱动的,那么你可以为每个应用程序运行 @SpringBootTest
,并模拟所有不需要的内容。顺便提一下,你提到的 MockMvc
并不会启动整个应用程序,而是启动与Web请求处理相关的 "部分" 应用程序(例如,它不会加载你的DAO层),所以这是完全不同的东西,请不要混淆它们
如果你想测试涉及所有6个服务的整个流程,你将需要运行一个完整的环境,并运行一个在远程JVM上执行的完整系统测试。
在这种情况下,你可以使用 TestContainers 将这些应用程序容器化,并在测试中运行它们。
显然,你还必须为数据库、消息传递系统等提供容器。
总而言之,我觉得这个问题相当模糊,缺乏具体的细节。
英文:
When it comes to @SpringBootTest
its supposed to load everything that is required to load one single spring boot driven application.
So the "integration testing" referred in Spring Boot testing documentation is for one specific application.
Now, you're talking about 6 already existing applications. If these applications are all spring boot driven, then you can run @SpringBootTest
for each one of them, and mock everything you don't need. MockMvc
that you've mentioned BTW, doesn't start the whole application, but rather starts a "part" of application relevant for web request processing (for example it won't load your DAO layer), so its an entirely different thing, do not confuse between them
If you wan't to test the whole flow that involves all 6 services, you'll have to run a whole enviroment and run a full-fledged system test that will be executed on a remote JVM.
In this case you can containerize the applications and run them in test with TestContainers.
Obviously you'll also have to provide containers for databases if they have any, messaging systems, and so forth.
All-in-all I feel that the question is rather vague and lacks concrete details.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论