Code Design and Testing

Learning Goals

  1. Create Python unit test functions that use assert statements to confirm that a function produces the expected result for a given input.
  2. Use the pytest tool to automatically discover, run, and report on unit test results.
  3. Explain the idea of baseline testing and how to automate it.
  4. Explain how modular code design, and the concepts of readability, encapsulation, and testability all contribute to the creation of robust, reusable code.

Code Design and Testing

Create and switch to a new testing branch in your repo. Create an testing directory and copy the climate_data.py from your automation directory file into it. Start ipython notebook in your testing directory.

The notebook we're going to work through is:

  • testing-0-unit-tests:

    • writing Python code to test our Python code
    • using pytest to automatically find, run, and report test results
    • using coverage to measure and report on unit test coverage of code
    • ideas about how to set up automated baseline testing

Most of the exercises will be done in your editor and at the command line.

The notebook for this lesson is available in this testing.zip archive.

References

Back to Topics