Automating Tests
One challenge we faced early on when implementing the back end and database, was how the testing of pull requests could be automated.
Docker image to maintain test reliability
After implementing the first few unit tests, we were confronted with the inefficiency of having to manually test routes using Postman when reviewing a PR. Given the project’s likely growth in both size and scope, this was not a sustainable solution.
Another challenge related to testing arose, this time related to maintaining the fidelity of the testing database. A good level of test coverage using Jest was achieved quickly, but with each team member using their own local testing database, the outcomes were not always reliable. To enforce testing reliability and control, the database needed to maintain a known state.
To achieve this objective, we implemented a PostgreSQL Docker image that would automatically spin up a Docker instance, set up and seed the database each time tests were run. One of the inherent advantages of using a Docker image is that unless explicitly set up, data does not persist after the Docker instance is shut down. We were able to take advantage of this property to avoid having to reset the database before running tests. This made the testing process more reliable and easier to control.
Github action to automating testing
To review a pull request, a reviewer would download the PR branch, run the test suite manually to ensure there had been no regression. Given the frequency of code changes and speed of development, we decided to implement automated testing to speed up the process, and make reviewers' job easier.
After some investigation, we settled on implementing GitHub Actions. We pointed automated tests on GitHub to the same PostgreSQL Docker image, seeded it with data as we would using on our local machines. As Alexandria’s code was already hosted on Github, this greatly simplified the review process. As tests results became available, they were displayed prominently on the PR, and the team was notified immediately should a problem arise.
This workflow greatly simplified the pull request and review process, saving us significant time in catching new bugs or dealing with regression issues.