简体   繁体   English

如何对 Spring Boot 应用程序进行集成测试?

[英]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.

相关问题 如何在Spring Boot集成测试中覆盖application.properties? - How to override application.properties in Spring Boot integration test? 这是在 Spring Boot 中进行集成测试的最佳方法吗? - Is it the best approach to do an integration test in spring boot? Spring 启动+集成测试 - Spring Boot + Integration Test 如何在Spring启动中集成测试库 - How to integration test repository in Spring boot 如何在使用 Spring Boot 的集成测试中自动装配存储库? - How autowire a repository in an integration test with Spring Boot? Spring Boot测试如何使用不同的application.properties进行集成测试 - Spring boot test how to use different application.properties for integration test 从 Spring Boot 集成测试运行原始应用程序 - Running the original application from Spring Boot integration test Spring Boot:集成测试不排除我的应用程序配置类 - Spring Boot : Integration Test not excluding my Application configuration class 如何通过 maven-failsafe-plugin 运行基于 spring-boot 的应用程序的集成测试? - How to run integration test of a spring-boot based application through maven-failsafe-plugin? Spring Boot 集成测试。 如何测试“删除”方法? - Spring Boot integration test. How to test the 'DELETE' method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM