50 likes | 194 Vues
Test-Driven Development (TDD) is a software development approach emphasizing testing before code implementation. The three fundamental rules of TDD are: 1) Write a failing unit test before any production code, 2) Only write as much unit test code as is needed to fail or compile, and 3) Only write enough production code to pass the failing test. TDD offers numerous advantages including ensuring all functions are testable, identifying when something breaks, providing a clear view from the caller's perspective, and serving as documentation through working examples.
E N D
Three Rules • Don’t write any production code until you have written a failing unit test. • Don’t write more of a unit test than is sufficient to fail or fail to compile • Don’t write any more production code than is sufficient to pass the failing test.
Advantages • All program functions are testable and have tests that verify their operation. • We can tell when we break something. • We see the function from the caller’s point of view. • The function will be “conveniently callable.” • Because the function is callable, we have decoupled it from other system software – e.g., the user interface. • Test provides documentation in the form of a working example.