Unit tests and Continuous Integration

Testing your code is a great way to make sure your code is working as expected and that new additions to your code do not break existing functionality. The first thing we need to test our code is unit tests. Unit tests are small tests that isolate certain functionality of your code. Ideally, your unit tests comprehensively cover a majority of the functionality in your code base.

We have added unit tests in our GitHub under PlotMAPQ/tests. There are three unit tests that test core functions and our command line tool. These tests use unittest to run tests.

To run the tests, we simply run:

make test

This triggers pytest to run using the command:

$(python) -m pytest -vv $(tests)

Continuous Integration with Travis

Once we have added unit tests, it would be helpful to automatically run tests every time our code changes. To do this, we can use existing continuous integration tools to test our code. Here, we choose to use travis-ci to run our tests. Travis-ci is free for public repositories, and can run unit tests every time code is updated or a pull request is made. You can find documentation for travis here.

Note that every repository that uses travis requires a .travis.yml file. You can find our travis file here. This file contains information on what build requirements your project has and how to run tests.

  1. To use Travis, first make an account. You will have to link this with your GitHub so it can access your repositories.
travis-createaccount
  1. Next, navigate to your user settings. You can toggle projects from your GitHub on and off.
travis-createproject

To see our unit tests in action, navigate to our Travis tests for this project.