Integration Testing with DynamoDB

Zhixuan Lai
2 min readJul 2, 2021

--

In this post, we will explore how to write an integration test for DynamoDB using tempest-testing.

Tempest-testing helps you test DynamoDB clients using DynamoDBLocal. It comes with two implementations:

  • JVM: This is the preferred option, running a DynamoDBProxyServer backed by sqlite4java, which is available on most platforms.
  • Docker: This runs dynamodb-local in a Docker
    container.

Feature matrix:

Tempest-testing ships a JUnit4 Rule and a JUnit5 Extension. It also supports both AWS SDK v1 and SDK v2. In the following example, we will use JUnit 5 and AWS SDK v2.

Initial setup

To use tempest-testing, first add this library as a test dependency:

For AWS SDK 1.x:

For AWS SDK 2.x:

Writing tests

Then in tests annotated with @org.junit.jupiter.api.Test, you may add TestDynamoDb as a test extension. This extension spins up a DynamoDB server. It shares the server across tests and keeps it running until the process exits. It also manages test tables for you, recreating them before each test.

Conclusion

That’s it! It takes as little as 4 lines of code to set up a test for your DynamoDB client.

Check out tempest-testing’s documentation.

Check out these code samples on Github:

  • Music Library — SDK 1.x (.kt, .java)
  • Music Library — SDK 2.x (.kt, .java)
  • Testing — SDK 1.x — JUnit4 — JVM (.kt, .java)
  • Testing — SDK 1.x — JUnit4 — Docker (.kt, .java)
  • Testing — SDK 1.x — JUnit5 — JVM (.kt, .java)
  • Testing — SDK 1.x — JUnit5 — Docker (.kt, .java)
  • Testing — SDK 2.x — JUnit4 — JVM (.kt, .java)
  • Testing — SDK 2.x — JUnit4 — Docker (.kt, .java)
  • Testing — SDK 2.x — JUnit5 — JVM (.kt, .java)
  • Testing — SDK 2.x — JUnit5 — Docker (.kt, .java)

--

--