All learning paths Learn See Try Make Run a test and read the result What this lesson is about Run somebody's tests, read which ones failed, and say what the failure tells you about the code.
You are handed a folder of code you have never seen. What do you do first?
A Read it through carefully first, and run the tests only if something looks off. B Run the tests before you form any opinion about somebody's code. C Run only the tests whose names look related to what you were asked about.
Check my recall Why this matters Running the tests is the fastest honest opinion you can have about code you did not write. It takes a minute and it needs no trust. A test name, the value it expected and the value it got say more than a page of guessing.
Run somebody else's tests and say what one failure tells you about their code.
Running the tests is the fastest honest opinion you can have about code you did not write. It takes a minute and it needs no trust. A test name, the value it expected and the value it got say more than a page of guessing.
Run the tests before you form any opinion about somebody's code. Read the failure block, not the count: the test, the expected value, the actual value. A passing run means the tests that exist passed, not that the code is right. Task You are sent a small billing program with its tests and asked whether it works.
Weak approach Reads the code for ten minutes and follows the billing function line by line. It looks correct and well written, so that is the reply. The test folder is never opened.
Stronger approach Runs the tests first. One goes red: test_round_paise wanted 12.35 and the code returned 12.3499. Says the rounding happens one step too late.
Why the stronger approach works The weak answer is an opinion about the reading. The strong one names the test, both values, and what they mean.
Try a changed situation A friend's project page shows a long log that ends in twelve passed and two failed. She asks what is broken. What do you look for?
Make something yourself Run the tests on any small program you can get. Write up one failure: the test name, the value expected, the value it got, and what it means.
Lesson 4 of 10 on Coding for evaluation work next Write one test that can fail Part 2 ends in a work sample you can send
Read the primary or official source: Python documentation · unittest