[英]How to do an integration test for a Spring Boot application?
TLDR: Should you test a compiled JAR or is it enough to write a @Test
method to run the main class? TLDR:您应该测试已编译的 JAR 还是编写
@Test
方法来运行主 class 就足够了?
I have a Spring Boot service that integrates with several other services.我有一个与其他几个服务集成的 Spring 引导服务。
Currently, in order to test the integration between the services I'm running the compiled JAR in sort of a staging environment while simulating the other services.目前,为了测试服务之间的集成,我在模拟其他服务的同时在一个暂存环境中运行编译的 JAR。
Is there a benefit of running the compiled JAR over running a unit test that runs the main application and mocks (eg using Mockito) the other services?运行已编译的 JAR 是否比运行运行主应用程序和模拟(例如使用 Mockito)其他服务的单元测试有好处?
Or maybe, do I need both of these capabilities?或者,我是否需要这两种能力?
It is likely that you'll want both.很可能你会想要两者。 This is a great guide on testing strategies for microservices https://martinfowler.com/articles/microservice-testing/
这是一个很好的微服务测试策略指南https://martinfowler.com/articles/microservice-testing/
The unit tests that test only a specific piece of your application with other parts of the internal application mocked.单元测试仅测试应用程序的特定部分,并模拟内部应用程序的其他部分。 These can run as part of your CI/CD pipelines.
这些可以作为 CI/CD 管道的一部分运行。
You'll also want to run integration tests in your codebase using mocks for external systems.您还需要使用外部系统的模拟在您的代码库中运行集成测试。 Those can run as part of your pipelines and use the test annotation you mentioned.
这些可以作为管道的一部分运行并使用您提到的测试注释。 These will ensure that your application functions correctly as long as the contracts to the external systems are correct.
只要与外部系统的合同正确,这些将确保您的应用程序正常运行。
Then you may want to do some runtime smoke testing as well against a running application using external tools that invoke your APIs.然后,您可能还想使用调用您的 API 的外部工具对正在运行的应用程序进行一些运行时冒烟测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.