Notes on TDD - chapter 1

Notes on TDD - chapter 1

February 11, 2024 | tdd, python

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.

  1. Add a little test
  2. Run all tests and fail
  3. Make a little change
  4. Run the tests and succeed
  5. 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)
    assert d.amount == 10

No notes link to this note

Go to random page