A unit test calls a function and checks the result.
PASS ☑ FAIL ☒
2017 tests passed in 225ms ☑
1/2017 tests failed in 228ms ☒
James O Coplien (2014?)
t = time.then() assert self.job(t) == "@SNSystems #BRI"
t = time.now() assert self.job(t) == "@ClinithinkWales #BGN"
git commit -m "Implement feature"
git commit -m "Fix the unit tests"
git commit -m "Fix the unit tests (again!)"
Unit tests which are brittle, large, slow, perpetually broken (and subsequently ignored), or flaky set bad examples which can get replicated through an entire test suite like a virus. Poorly-written tests can actually be worse than no tests at all, leaving the impression that testing is a waste of time.
Mike Bland, Goto Fail, Heartbleed, and Unit Testing Culture
import random def test_sort(): xs = list(range(10)) random.shuffle(xs) xs.sort() assert all(a < b for a, b in zip(xs, xs[1:]))
def test_sort(): ins_outs = ( ([], []), ([1], [1]), ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]), ([5, 4, 3, 2, 1], [1, 2, 3, 4, 5]), ([4, 2, 1, 5, 3], [1, 2, 3, 4, 5]), ([6, 6, 6], [6, 6, 6])) for i, o in ins_outs: i.sort() assert i == o
Professor Sir Tony Hoare is right ✔
James O Coplien isn’t ✘
Donald Knuth is being serious!