LocalStack provides an easy-to-use test/mocking framework for developing Cloud applications. It's helpful to test AWS services locally or on Build Agent because it works based on mocks and we don't have to pay for Amazon Services.
- You have to add dependencies on:
cloud.localstack:localstack-utils- aws sdk. Localstack supports aws sdk v1 and v2 (at this example aws sdk v2 was used)
- aws sdk v1 usually has packages starting with
com.amazonaws:aws-java-sdk - aws sdk v2 usually has packages starting with
software.amazon.awssdk:
- aws sdk v1 usually has packages starting with
- Localstack runs docker containers with AWS mocks locally.
- Localstack containers can be run from tests as follows:
- Under junit4 with marking test with
@RunWith(LocalstackTestRunner) - Under junit5 with marking test with
@ExtendWith(LocalstackDockerExtension.class)
- Under junit4 with marking test with
- At this project there are 2 IT tests with Localstack
S3ExampleITSqsExampleIT- These tests can be run locally
- Or on Gitlab runner as part of
integrationTesttask.- See
ittask ingitlab.ci - Gitlab schedule
Run IT test-> https://gitlab.inventale.com/platform/templates/localstack-example/pipeline_schedules/55/edit
- See
- Localstack tests cannot be run concurrently - that's why there is special ordering mechanism for gradle
integrationTesttasks. See details at:s3/build.gradle.kts:31sqs/build.gradle.kts:29- sorting at
build.gradle.kts:30
If your testcase failed then it can happen that Docker container is still alive and you can't run test again
- In this case please find your container by typing
docker container lsin terminal - Get Container ID and execute
docker container rm {CONTAINER ID} -f, please replace{CONTAINER ID}with real container id