Overview of automated testing

Case Study: Building Software in Python

Mark Pedigo

Principal Data Scientist

Roadmap

Roadmap showcasing what parts of the project we've finished and which we'll be starting.

Case Study: Building Software in Python

Automated Testing and the Development Workflow

  • Correct, predictable results
  • Predefined test cases
  • Automatic execution

A computer with a screen showing the words "automated testing" surrounded by bugs and gears, representing automated testing.

Case Study: Building Software in Python

The doctest library

  • Automated testing: doctest, pytest
  • Use docstrings to describe code
  • doctest: Validate docstring examples
Case Study: Building Software in Python

Features of the doctest library

  • Inline testing
  • Easy to use
  • Documentation as tests
  • Supports regression testing
Case Study: Building Software in Python

Example Use

def area(l, w):
    """
    Finds the area given length and width and returns the result
    >>> area(1, 1)
    1
    """
    return l + w

import doctest
doctest.testmod()
Case Study: Building Software in Python

Example Use

Failed example:
    area(1,1)
Expected:
    1
Got:
    2
Case Study: Building Software in Python

Example Use

def area(l, w):
    """
    Finds the area given length and width and returns the result
    >>> area(1, 1)
    1
    """
    return l * w

import doctest
doctest.testmod()

Everything OK = no error messages, no output

Case Study: Building Software in Python

Let's practice!

Case Study: Building Software in Python

Preparing Video For Download...