Oct 16: Unit Testing with pytest
Learning Objectives
After today's class, you should be able to:
- Install and run pytest on your computer.
- Explain the role of
assert
in unit tests. - Write unit tests for both modules of PA1.
Announcements¶
- Mid-Eval survey – LAST CALL!
- Worth 5 pts like everything else
- Ch 8 on zyBooks – due Tuesday
- PA 1 Poker Dice (modules + testing)
- Readiness Quiz now available
- Part A due Tuesday 10/24 (30 pts)
- Part B due Tuesday 10/31 (70 pts)
Pytest Tutorial¶
[30 min]
- Installing/Running pytest
- If you are absent today, complete this tutorial on your own
- Bring your completed
test_triangles.py
to office hours
PA1 Unit Tests¶
[20 min]
Here is a starting point for Part A of the project.
Two example assert
statements are provided for each test function.
You should add at least three more to each function,
so that every requirement of the project is tested.
Note: Docstrings are generally not required for test functions. But you should still have a module docstring with your name and date.
test_dice.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
On Part B, you will need to define a test function for each of the nine categories.
Each test function should have at least five assert
statements.
(The autograder has over ten assert
statements in each category!)
Don't just add assert
statements for the sake of having five or more.
Make sure you test each situation required by the project.
Note: The following code abbreviates score_dice
as sd
,
rather than import every constant.
test_score_dice.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 |
|