Skip to content

Unit Testing guide

Victor Hong edited this page Dec 13, 2018 · 2 revisions

Backend

For the backend we have one file 'factories.py' which contains a class that creates the following objects: User, Account, Event, and last School. These factories classes will be used to unit test each user stories.

For instance we have Event test, for this test we need to first create a Account that includes a user and school. Now we have a made up user that can create, delete, join event. And lastly we have Event guest test, for this test like before we need to create a Account that includes a user and school. Now we have a made up user that can join, join when full, leave and check the guest list from the event created in the previous test. All this already test all user cases since this is a continuous test of each feature.

Frontend

Testing on the frontend uses Jest, Enzyme, and npm to create and run our tests. The majority of our tests are around our React components and making sure they render correctly as well as validating props and state. In some of our components we employ Jests' snapshot testing feature to capture the rendered instance and comparing the existing one to the snapshot making sure it's on a working instance of the component. The tests are ran whenever we push to master through our CI/CD and can also be manually initiated using npm run test in the frontend root directory.

Tests should be in a __tests__ folder which would automatically be detected by npm. Tests can also be written in the foo.test.js format which npm will also detect.