Integration Tests in a Cloud Foundry Java App
During development of our Cloud Foundry Java app we came to a point where we wanted to test our code automatically in integration tests.
What are Integration Tests?
In our case, an “integration test” is a test that runs within JUnit as part of the build and that tests a set of multiple production classes in combination. In the test pyramid, these integration tests form the layer directly on top of the “pure” unit tests that each test a single production class or method, on its own.
Unit and integration tests need to be complemented by things like system tests and performance tests to verify other aspects of the system, such as user acceptance or behavior under load. However, these latter kinds of tests are much slower, more fragile and thus more expensive to write and maintain, and according to the test pyramid therefore should be replaced by simpler unit and integration tests wherever possible.
How We Do Integration Tests
Since we use Spring Boot in our Java application, we decided to write the integration tests as @SpringBootTests. While writing the tests, we faced some challenges with the used components, such as the SAP Cloud SDK or the SAP Cloud Application Programming Model, and certain aspects, such as verifying the security configuration of the endpoints.
After some investigation, we found a way to meet all these challenges, and we’d like to share our insights. The blog posts linked below demonstrate our way to test our coding. The posts show the setup needed for testing and what can be tested with it (and what not). They focus on the challenges specifically with the used components.
If you’d like to read up on Spring Boot tests first, kindly refer to Spring Testing and Spring Boot Testing.
Our Service Setup
- Java 8 application
- Build tool: Maven
- Spring Boot 2.x.x
- Java security 2.x.x
- Dependency: com.sap.cloud.security.xsuaa:spring-xsuaa
- Cloud Application Programming Model (CAP) 1.x.x using OData version 2
- Dependency: com.sap.cloud.servicesdk.prov:odatav2-spring-boot-starter
- Cloud Application Programming CDS data store
- SAP Cloud SDK 2.x.x
- Dependency: com.sap.cloud.s4hana.cloudplatform
- SAP Enterprise Messaging
The following blog posts describe the individual testing parts of our application, especially the configuration and setup.
With the additional setup described in the linked blog posts, typical SAP Java cloud applications can be covered up to 100% with Spring Boot integration tests, giving our test pyramid a stable foundation.