Simple project to apply Test Pyramid methodology together with Clean Architecture There are some code samples showing how to test on each layer of the pyramid, from bottom to top, and how each layer exercises a real component or use an emulated one:
The Business Class (or Utility Class) to be tested has all its internal objects emulated with a Mock instance (expected input and output defined on Test Class), and widely tested to cover all input variations and expected results. Examples:
The Business Class to be tested has all its Integration Resorces (Data Provider, or even a External Resource Client) executed with the real instances, and the final resource emulated with an on-memory database (like H2) initialized right before the Test, and discarded at end, or emulated with a WireMock instance with expected requests and payloads. In this layer the tests have less scenarios, only covering the external resource's variations. Examples:
The role application is tested calling all it's entrypoints, but still emulating external resources (like example above). In this layer the tests have fewer scenarios, only covering the entrypoints input and output variations. Examples:
- Microservice
- Spring Cloud Contract
- Wiremock
The role application is tested in a dedicated environment, where all external resources are real, most similar to production environment as it's possible. In this layer the tests are still made with an automated tool, but only cover the scenarios where the data has a state.
The role application is tested in a dedicated environment, where all external resources are real, most similar to production environment as it's possible. In this layer the tests are usualy made by a human, on pre-defined scenarios based on final user experience.
- https://martinfowler.com/articles/microservice-testing/#conclusion-summary
- https://martinfowler.com/bliki/TestPyramid.html
- https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html
- Unit Testing:
- https://cloud.spring.io/spring-cloud-contract/
- https://reflectoring.io/consumer-driven-contract-consumer-spring-cloud-contract/
- Component and Integration Testing:
- https://gatling.io/docs/current/