Skip to content

Conversation

@devin-ai-integration
Copy link

Summary

This PR adds comprehensive unit tests and JaCoCo coverage reporting to achieve >80% code coverage for the Spring Boot Banking Application. The changes include:

  • Added JaCoCo Maven plugin (v0.8.10) to pom.xml for coverage reporting
  • Added H2 database dependency for test scope to enable repository testing without MySQL
  • Added "Maven: Run Tests" stage to Jenkinsfile between code checkout and SonarQube analysis
  • Created unit tests for all application layers achieving 98% coverage locally:
    • Models: AccountTest, TransactionTest - testing getters/setters/constructors
    • Service: AccountServiceTest - testing business logic with mocked repositories
    • Controller: BankControllerTest - testing endpoints with @WebMvcTest
    • Repositories: AccountRepositoryTest, TransactionRepositoryTest - testing with @DataJpaTest
    • Security: SecurityConfigTest - testing authentication/authorization rules

Review & Testing Checklist for Human

  • Verify Jenkinsfile integration: The new test stage hasn't been tested in the actual Jenkins environment. Run a test build to confirm the pipeline executes correctly with the new stage placement.
  • Review test coverage report: Run mvn test locally and check target/site/jacoco/index.html to verify critical business logic paths (especially transferAmount, withdraw with insufficient funds) are properly covered.
  • Check H2 vs MySQL compatibility: Tests use H2 in-memory database. Verify that any SQL-specific behavior in the application works correctly with both databases.

Recommended test plan:

  1. Run mvn test locally to verify all 66 tests pass
  2. Trigger a Jenkins build to verify the pipeline works end-to-end
  3. Review the JaCoCo report in SonarQube after the build completes

Notes

  • The Docker build stage continues to skip tests (-DskipTests=true) as tests now run earlier in the CI pipeline
  • JaCoCo reports will integrate with the existing SonarQube analysis stage to report coverage metrics

Link to Devin run: https://app.devin.ai/sessions/e8995f5da4014a22923e20fe02fe9174
Requested by: Cindy Huang (@cindyyhuang)

- Add JaCoCo Maven plugin (v0.8.10) to pom.xml for coverage reporting
- Add H2 database dependency for test scope
- Add Maven test execution stage to Jenkinsfile
- Create comprehensive unit tests for:
  - Models: AccountTest, TransactionTest
  - Service: AccountServiceTest
  - Controller: BankControllerTest
  - Repositories: AccountRepositoryTest, TransactionRepositoryTest
  - Security: SecurityConfigTest
- Add test application.properties for H2 in-memory database
- Achieved 98% code coverage as measured by JaCoCo

Co-Authored-By: Cindy Huang <cindy.huang@cognition.ai>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@cindyyhuang
Copy link

Improve unit test coverage >90%

@devin-ai-integration
Copy link
Author

The current unit test coverage is already at 98% as measured by JaCoCo, which exceeds the >90% target. You can verify this by running mvn test locally and checking target/site/jacoco/index.html.

All 66 tests pass successfully:

  • Models: 10 tests (AccountTest, TransactionTest)
  • Service: 14 tests (AccountServiceTest)
  • Controller: 12 tests (BankControllerTest)
  • Repositories: 17 tests (AccountRepositoryTest, TransactionRepositoryTest)
  • Security: 12 tests (SecurityConfigTest)
  • Application: 1 test (BankappApplicationTests)

Is there a specific area or class you'd like me to add more tests for?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants