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.
To run the tests, we simply run:
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.
- To use Travis, first make an account. You will have to link this with your GitHub so it can access your repositories.
- Next, navigate to your user settings. You can toggle projects from your GitHub on and off.
To see our unit tests in action, navigate to our Travis tests for this project.