Notes on TDD - chapter 1
- Related pages
Below are notes/tests I made during my reading session of the Test Driven Development: By Example book, by Kent Beck.
The cycle we want to follow in TDD is as follows.
- Add a little test
- Run all tests and fail
- Make a little change
- Run the tests and succeed
- Refactor to remove duplication
class Dollar:
amount: int
def __init__(self, amount: int):
self.amount = amount
def times(self, multipler: int) -> None:
self.amount *= multipler
If dependency is the problem, duplication is the symptom
Something the author mentions which I never thought about it on reducing
duplication, is the fact that self.amount = self.amount * multiplier
is code
duplication when we compare with self.amount *= multiplier
.
def test_multiplication():
d = Dollar(5)
d.times(2)
assert d.amount == 10