Skip to content

feat: replace external dependencies with mocks in unit tests #1946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Gdm0714
Copy link

@Gdm0714 Gdm0714 commented Jul 19, 2025

  • Remove DynamoDB Local dependency from unit tests
  • Replace integration tests with proper unit tests using Mockito
  • Add E2E test scenario for real AWS infrastructure validation
  • Improve test performance and reliability by eliminating external dependencies
  • Add mockito-core dependency to powertools-idempotency-dynamodb module

Summary

Changes

Please provide a summary of what's being changed

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: #1932

  • Removed DynamoDB Local dependency: Eliminated DynamoDBLocal and libsqlite4java-osx-aarch64 dependencies from powertools-idempotency-dynamodb module
  • Implemented Mockito-based unit tests: Replaced DynamoDBConfig server setup with @mock annotations and proper unit test patterns
  • Updated DynamoDBPersistenceStoreTest: Converted integration-style tests to isolated unit tests that verify business logic without external dependencies
  • Enhanced E2E test coverage: Added real AWS infrastructure test scenario in IdempotencyE2ET for comprehensive integration testing
  • Added Mockito dependency: Included mockito-core test dependency to support the new mocking approach
  • Simplified test setup: Removed complex server startup/shutdown logic and port management code

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

- Remove DynamoDB Local dependency from unit tests
- Replace integration tests with proper unit tests using Mockito
- Add E2E test scenario for real AWS infrastructure validation
- Improve test performance and reliability by eliminating external dependencies
- Add mockito-core dependency to powertools-idempotency-dynamodb module
@phipag
Copy link
Contributor

phipag commented Jul 19, 2025

Hi @Gdm0714, thank you very much for sending this PR. I will review it next week in more detail.

In the meantime, can you have a look at the 7 new Sonarlint issues? https://sonarcloud.io/project/issues?id=aws-powertools_powertools-lambda-java&pullRequest=1946&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true

  • For example, we can remove all public modifiers in unit tests since in Junit5 all classes and methods in unit tests can use the default package private scope.

One question as well:

  • Can you explain the additional coverage that you added in the Idempotency E2E test? I don't understand why this is necessary.

@Gdm0714
Copy link
Author

Gdm0714 commented Jul 19, 2025

Hi! Thank you for the feedback and for taking the time to review this PR.

I'll address the SonarLint issues you mentioned:

  • I'll update all test classes and methods to use package-private scope as recommended for JUnit 5.

  • You're absolutely right to question this. Looking back at the changes, the additional E2E test scenario I added (test_idempotencyWithRealDynamoDBTable) is actually redundant since the existing E2E tests
    already cover idempotency functionality with real AWS infrastructure.

The main goal of this PR was to replace external dependencies (DynamoDB Local) with mocks in unit tests, not to add more E2E coverage. I can remove this additional E2E test method to keep the scope focused.

Let me push the fixes for

  • Remove public modifiers from test classes/methods
  • Remove the unnecessary additional E2E test
  • Address other SonarLint issues

Thanks again for the review!

- Remove public modifiers from test classes and methods (JUnit5 package-private scope)
- Remove unused imports (ResourceNotFoundException, Collections)
- Remove unnecessary E2E test method for better scope focus
Copy link

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