JUnit 5 extensions for AWS

Posted on 2019-09-26
3 mins to read

Do you test the code that uses AWS services?
Do you use JUnit 5 in your tests?
If you do both, I may have something useful for you.

JUnit 5 extensions for AWS: a few JUnit 5 extensions that could be useful for testing AWS-related code.
These extensions can be used to inject clients for AWS service mocks provided by tools like localstack.
Both AWS Java SDK v 2.x and v 1.x are supported.

You may know (or you may imagine, if you never tried) that testing code that works with AWS is not easy.
Just mocking the clients is enough only for simple unit tests, it won’t help you detect some service-specific issues like this:

What’s wrong with this code?
If you mock the client, there are basically two outcomes: either it accepts your request or it fails.
But the real AWS service client will always fail.
Kinesis requires partition key:

This is true for every other AWS services: DynamoDB’s getItem requires table name and key, S3 requires bucket and key for putObject and so on.

Here, at the level of integration testing, come tools like localstack, MinIO or DynamoDB Local.
The idea is to mock an AWS service using a low-cost, disposable (in-memory) implementation and use it to test your code.
Localstack already supports two dozen of AWS services and the list is growing!

You only have to get the clients in your test classes, and aws-junit5 will help you do with a minimal effor: