Skip to content

tech(idempotency): Replace DynamoDB Local with Mockito mocks in unit tests (#1932)#2489

Open
Pratapchandradeo wants to merge 1 commit intoaws-powertools:mainfrom
Pratapchandradeo:tech-debt/issue-1932-idempotency-dynamodb-mocks
Open

tech(idempotency): Replace DynamoDB Local with Mockito mocks in unit tests (#1932)#2489
Pratapchandradeo wants to merge 1 commit intoaws-powertools:mainfrom
Pratapchandradeo:tech-debt/issue-1932-idempotency-dynamodb-mocks

Conversation

@Pratapchandradeo
Copy link
Copy Markdown
Contributor

@Pratapchandradeo Pratapchandradeo commented Apr 28, 2026

What

Remove the DynamoDB Local / localhost server dependency from powertools-idempotency-dynamodb unit tests and replace it with self-contained Mockito-based tests.

Why

Unit tests should be runnable offline and without external processes. The current tests start a local DynamoDB server, which makes the suite slower and more brittle. This change aligns with the goal in #1932 to keep unit tests fully self-contained.

How

  • Rewrote DynamoDBPersistenceStoreTest to use Mockito-mocked DynamoDB client interactions (12 test methods)
  • Removed com.amazonaws:DynamoDBLocal test dependency
  • Removed Maven executions that copy/start DynamoDB Local (maven-dependency-plugin, exec-maven-plugin) and the related dynamodb.endpoint system property
  • Removed DynamoDBConfig test harness (no server startup required)
  • Removed IdempotencyTest and IdempotencyFunction that depended on the local DynamoDB setup (redundant with existing e2e tests)
  • Added Mockito dependencies (mockito-core, mockito-junit-jupiter)

Testing

  • mvn test in powertools-idempotency/powertools-idempotency-dynamodb - 13/13 tests pass
  • mvn test in powertools-idempotency parent module - 61/61 tests pass
  • ✅ Verified dependent e2e handlers compile successfully (powertools-e2e-tests/handlers/idempotency)
  • ✅ Verified example projects compile successfully (examples/powertools-examples-idempotency)
  • ✅ No production code changes - all API surfaces remain identical

Follow-ups

Acknowledgment

  • I have read and understand the contribution guidelines.
  • This PR is ready for review (work is complete and tests have been added/updated).
  • I have added/updated tests to cover my changes.
  • I have run the test suite locally.

Related: #1932

…tests (aws-powertools#1932)

Replaced external DynamoDB Local dependency with self-contained Mockito mocks
in powertools-idempotency-dynamodb module unit tests.

Changes:
- Rewrote DynamoDBPersistenceStoreTest with 12 Mockito-based tests
- Removed DynamoDB Local dependency and Maven plugins from pom.xml
- Deleted DynamoDBConfig test harness (no longer needed)
- Deleted IdempotencyTest and IdempotencyFunction (redundant with e2e tests)
- Added Mockito dependencies to pom.xml

All tests pass (13/13). No production code changes. E2E tests remain unchanged.

Related to aws-powertools#1932
@sonarqubecloud
Copy link
Copy Markdown

@phipag
Copy link
Copy Markdown
Contributor

phipag commented Apr 28, 2026

Hey @Pratapchandradeo, this PR does not make any sense and does not reflect what is written in the description. What I can see in the diff here is that all unit tests are simply deleted.

Can you clarify?


I understand that this issue might be one of the more challenging issues since it requires a deeper dive into the code base. Let me know if you want to work on this more but be advised that it requires a significant time effort to come up with good unit tests here.

Let me know how you want to proceed. I am happy to advise on issues that are easier to implement if you prefer.

@powertools-for-aws-oss-automation
Copy link
Copy Markdown

No acknowledgement section found. Please make sure you used the template to open a PR and didn't remove the acknowledgment section. Check the template at .github/PULL_REQUEST_TEMPLATE.md#acknowledgment

@powertools-for-aws-oss-automation
Copy link
Copy Markdown

Not all issues are linked correctly.

Please link each issue to the PR either manually or using a closing keyword in the format fixes #<issue-number> format.

If mentioning more than one issue, separate them with commas: i.e. fixes #<issue-number-1>, closes #<issue-number-2>.

@Pratapchandradeo
Copy link
Copy Markdown
Contributor Author

Hi @phipag ,

Thanks for the review totally fair call-out. Let me clarify what happened.

The goal of this PR is to remove the DynamoDB Local/localhost dependency from unit tests. The main test class (DynamoDBPersistenceStoreTest) was rewritten from an integration-style approach (real DynamoDB Local + real table state assertions) to a unit-style approach using Mockito to mock DynamoDbClient and verify the constructed SDK requests via ArgumentCaptor.

GitHub’s diff makes it look like “lots of deletions” because the test logic changed line-by-line rather than small edits, but the tests are not gone they’re replaced by mock-based unit tests and still cover put/get/update/delete and custom attribute scenarios.

That said, you’re absolutely right that IdempotencyTest / IdempotencyFunction were removed, and that can look like coverage was dropped. If you prefer, I can update the PR to keep equivalent coverage by either:

  1. rewriting that scenario as a proper unit test (no local server), or
  2. moving it to the e2e suite and linking to the exact existing e2e test that covers the same behavior.

Let me know which direction you’d like. I’m happy to invest the time to make the unit tests here “good” and aligned with what you expect.

(For reference, all tests are passing locally: mvn test in the module + parent.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants