derjust / spring-data-dynamodb

This module deals with enhanced support for a data access layer built on AWS DynamoDB.
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
403 stars 141 forks source link

Unit Testing Strategies/Recommendations? #217

Open pluttrell opened 6 years ago

pluttrell commented 6 years ago

Are there any strategies, recommendations and/or examples for unit testing our implementations that use this library without connecting directly to and reading/writing from live DynamoDB tables?

For example I know that AWS provides DynamoDBLocal, and I see that it's used in a couple of cases within the project's unit tests. But I haven't had success wiring this up, so thought I'd reach out to see if this is the correct path and if anyone hand any examples and doing this.

derjust commented 5 years ago

As part of #17 there are coming some simplification & helper classes that can also be used by consuming projects. I.e. check out CRUDOperationsIT.java on Branch Issue-17:

@RunWith(SpringJUnit4ClassRunner.class)

Use whatever runner allows you to have Spring running

@ContextConfiguration(classes = {DynamoDBLocalResource.class, YourTestAppConfig.class})

DynamoDBLocalResource starts the in-memory DynamoDB & use any app config to bootstrap your additional beans

@TestPropertySource(properties = {"spring.data.dynamodb.entity2ddl.auto=create"})

Let the tables (in the in-memory DynamoDB) be created on each run automatically.