Skip to content

Testing

Brandon Li edited this page Jun 8, 2021 · 3 revisions

This document describes how to write unit tests for our backend. For full context on the decisions made for testing, see the Backend Unit Testing document.

Writing Tests

Technologies

Prerequisites

  1. Install MongoDB Community Edition locally if you haven't already.

  2. Start mongodb locally (in a separate tab) using the mongo shell, and get the outputted connection URL.

    mongo --host localhost # IMPORTANT: make sure you have it on localhost, and not something like 127.0.0.1
  3. Add the TESTING_MONGO_URL to the .env file. This is the outputted url. For example, it should look something like:

    TESTING_MONGO_URL=mongodb://localhost:27017/?compressors=disabled&gssapiServiceName=mongodb
    
  4. Run make install

  5. Run tests with make test

Testing Philsophy

What are we testing?

We are testing our controllers and middleware. Full routing tests will be saved for integration/end-to-end testing.

What is a unit test?

  • Isolated and does not rely on external dependencies
  • Can run concurrently with other tests
  • Consistent and deterministic in its results
  • Easy to debug on failure

Clone this wiki locally