Lab 10—Unit testing
Objectives
- Practice unit testing
- Please pair program today!
Exercise
First, review the Python 3 unittest framework documentation.
Next, clone a copy of the Lab08-Files repository.
git clone https://github.com/lizboese/CU-CSCI3308-PythonUnitTesting
This repository includes a simple Python 3 module with a class called
Processor
that performs some basic analysis methods on the input text. Review
the Lab08-Files for details.
The repository also contains the start of a Python 3 unittest file: textproc_test.py
.
Execute this file to confirm that the single, initial unit test passes.
Questions
Add the following tests to the textproc_test.py
file:
- Write a test to verify the constructor raises an error if passed something other than a string
- Write one or more unit tests to test the
count()
method - Write one or more unit tests to test the
count_alpha()
method - Write one or more unit tests to test the
count_numeric()
method - Write one or more unit tests to test the
count_vowels()
method - Write one or more unit tests to test the
is_phonenumber()
method - Find and correct any bugs the tests turn up
Credit
To get credit for this lab exercise, show the TA and sign the lab’s completion log.
Lab material by Liz Boese.