Gergő Pintér, PhD
gergo.pinter@uni-corvinus.hu
the turtle and rabbit figures by Delapouite under CC BY 3.0 via game-icons.net
a unit test is another piece of code, that tests the given unit
parts of a unit test
there is no open standard for categories
these are from the book xUnit test patterns: Refactoring test code – by Gerard Meszaros [4]
As the tests get more specific, the code gets more generic.
– Robert C. Martin, The Cycles of TDD [5]
code/fizzbuzz.py
code/test_fizzbuzz.py
test coverage: 70%
test coverage: 90%
test coverage: 100%
four control flow branch, all of them needs to be tested
it is hard to objectively measure the quality of code
def calculate_progress(
finished: int,
total: int,
as_percentage: bool,
) -> float:
progress = finished / total
if as_percentage:
return progress * 100
else:
return progress
this function need some value checking
test coverage only measures that every control flow branch is tested
the point of testing is testing for the edge cases
add feature | fix a bug | refactor | optimize | |
---|---|---|---|---|
structure | changes | changes | changes | |
new funcionality | changes | |||
functionality | changes | |||
resource usage | changes |
Michael Feathers, Working Effectively with Legacy Code: part 1 pp 6 [6]
black box
white box