Pick one bug/missing feature Write a test that fails Write enough code to pass the test Refactor the code Split the problem into small manageable units of work.
Pick one bug/missing feature Write a test that fails Write enough code to pass the test Refactor the code If the test you wrote doesn’t fail ask yourself “Is this test useful?” (which doesn’t mean “the test is useless”, it means “ask yourself”)
Pick one bug/missing feature Write a test that fails Write enough code to pass the test Refactor the code Your goal is to pass the test. More code = more (potential) bugs + more maintenance.
Pick one bug/missing feature Write a test that fails Write enough code to pass the test Refactor the code NEVER refactor without tests. How can you be sure the refactored code still works?
The goal of the project is to write a class SimpleCalculator that performs calculations: addition, subtraction, multiplication, and division. Addition and multiplication shall accept multiple arguments. Division shall return a float value, and division by zero shall return the string "inf". Multiplication by zero must raise a ValueError exception. The class will also provide a function to compute the average of an iterable like a list. This function gets two optional upper and lower thresholds and should remove from the computation the values that fall outside these boundaries. Project requirements
Tests for the average function Average of an iterable (list, tuple) Upper threshold (if > U don’t use it) Lower threshold (if < L don’t use it) Check that thresholds are not included Average of an empty iterable Average of an empty iterable (after thresholds) Thresholds applied to an empty iterable Argument is not iterable Project requirements
https://www.thedigitalcatonline.com/categories/tdd/ I'm too young to die TDD in Python with pytest (5 posts) Useful pytest command line options Refactoring with tests in Python: a practical example Hurt me plenty Python Mocks: a gentle introduction (2 posts) Nightmare! A game of tokens: write an interpreter in Python with TDD (4 posts and counting) Clean architectures in Python: a step-by-step example Posts I wrote on TDD