Skip to content

Conversation

timler
Copy link
Contributor

@timler timler commented Jan 17, 2025

Description

This PR adds

  • automated tests (both integration and unit) to the project using Jupiter, Mockito and Test Containers.
  • Github PR template
  • Github Workflow for Continuous Integration

To allow for tests to run, we had to make some other changes:

  1. There are changes to ApplicationConfiguration to enable the use of application-test.properties, and to allow for environment variables. These changes are backwards compatible.
  2. Added Flyway, which allows us to manage the database updates. Currently this is disabled for the main application

Type of change

  • Test Update

Testing

  • Unit Tests Added/Updated
  • Integration Tests Added/Updated
  • Manual Testing Completed
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 41.773 s - in cc.altius.FASP.jwt.resource.JwtAuthenticationRestControllerIntegrationTest
[INFO] Running cc.altius.FASP.integration.UserRestControllerIntegrationTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.589 s - in cc.altius.FASP.integration.UserRestControllerIntegrationTest
[INFO] Running cc.altius.FASP.service.impl.UserServiceImplTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.902 s - in cc.altius.FASP.service.impl.UserServiceImplTest
[INFO] Running cc.altius.FASP.WebApplicationTests
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.338 s - in cc.altius.FASP.WebApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0

Test Cases

  1. Tested with and without the environment variable QAT_HOMEFOLDER instead of changing application.properties
  2. Tested running the app with and without Flyway enabled

Deployment Instructions (optional)

To run all the tests:

./mvnw test

To run a single test:

./mvnw clean test -Dtest=cc.altius.FASP.jwt.resource.JwtAuthenticationRestControllerIntegrationTest

QA Instructions (optional)

To set your environment variable for QAT_HOMEFOLDER:

export QAT_HOMEFOLDER='<your home folder>'
echo $QAT_HOMEFOLDER

To remove the environment variable:

unset QAT_HOMEFOLDER
echo $QAT_HOMEFOLDER

To test Flyway:

  • Add an SQL script to /src/main/resources/db/migration
  • See README.md in that folder

Breaking Changes

  • No breaking changes

Dependencies

Added:

  • Flyway
  • Jupiter
  • Mockito

Related Tickets & Documents

Screenshots/Recordings

Checklist

  • Code follows style guidelines
  • Self-review completed
  • Tests pass locally
  • Documentation updated
  • No new warnings generated

Additional Notes

Documentation can be viewed here:

adanje and others added 9 commits January 13, 2025 09:41
Created a foundational test setup to enable writing tests across the
application. Added integration and unit tests for UserRestController
and JwtAuthenticationRestController to validate their functionality and improve code coverage.
Added application-test.properties to allow for a separation of application
and test properties using Spring profiles. Documented and refacted
ApplicationConfiguration to check the Spring profiles - this should be
done automatically by Spring but as we are using a property to define
the location of the other property files (under QAT_HOME), it needs to
be done manually. Also added the option to define QAT_HOME as an
environment variable and tested that any property can be overriden with
an environment variable (which will be used in the CI/CD pipeline).
- Create TestMySQLContainer as singleton for efficient test execution
- Move SQL scripts to test resources for better organization
- Set JaCoCo coverage minimum to 0% temporarily
- Move @SpringBootTest to AbstractIntegrationTest
- Move @AutoConfigureMockMvc to AbstractIntegrationTest
- Move @activeprofiles("test") to AbstractIntegrationTest
- Update shouldReturnUserDetails to expect success result
Implemented Flyway for the DB management; the solution will need to change
when Flyway is implemented for the whole application - e.g. the migrations
should be added under src/main/resources so the scripts are only added
to the source code once.
Moved the tests so that they match the package of the class they are
testing. This means that we don't need to improve the classes that are
being tested and makes life easier and simpler.
Finished the implementation for Flyway for the application itself. It
is currently turned off (via the properties) but when it is enabled we
can put our database scripts into the folder src/main/resources/db/migrate
with a version prefix e.g. `V1__` and they will be automatically run
in the application's database
Created a PR template to enforce best practises when developers and
implementers open PRs in the code. They will be prompted to fill in
details about their work and provide clear descriptions and details.
Created a CI pipeline using Github Actions to perform a build and test
on every push to the repo
@timler timler changed the title Automated tests Automated tests & Continuous Integration Jan 17, 2025
@timler timler changed the title Automated tests & Continuous Integration Automated tests & Continuous Integration Pipeline Jan 17, 2025
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.

1 participant