Week 5

Unit tests

A test calls one function and checks the result. You can run that check again whenever you change the function.

A unit test calls one function with an input you chose and checks the return value. Assert says 'this must be true'. If it is not, you get an AssertionError and pytest marks that test failed. The point is to notice a broken function without clicking through the program yourself.

The function under test should return a value, not print it. Print is for the person at the keyboard. Return is for the test. If your old program only printed, this week asks you to pull the decision out into a function the test can call.

A fresh example: a function that doubles a number. One test passes 2 and expects 4. Another passes 0 and expects 0. You run pytest and both should pass. That function is not a problem set.

The idea
Call, expect, report Call a function Expect a result Pass or fail

Problems