test-driven-development
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| test-driven-development [February 18, 2026 at 18:48] – yanevskiv | test-driven-development [May 14, 2026 at 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # Test-driven development | ||
| + | **Test-driven development** (or **TDD**) is a practice where you apprach software development in the following way: | ||
| + | |||
| + | 1. You write a test. This test fails immediately, | ||
| + | 2. You write the smallest piece of code that passes your test *and add nothing else*. | ||
| + | 3. You refactor the code and improve design while keeping all your tests working. | ||
| + | |||
| + | Then you add another test (which, again, fails by default), you write code that passes the test, you refactor the code so all your tests keep working, et cetera. | ||
| + | |||
| + | This way, tests actually " | ||
| + | |||
| + | But why do it this way? Because when you frontload writing tests, you tend to write rigorous detailed tests that cover almost all edge cases you can think of! You also get an intuition how your code will actually be *used*, rather than just *implemented*. And most of all, all your code will be thoroughly tested (as long as you follow the italic part in step 2 ;). | ||
| + | |||
| + | Let's compare it to the traditional way -- *code first, test later*. | ||
| + | |||
| + | Well, what's the issue with that? Commonly what happens is you write a lot of code that does a lot of things -- because programming is fun! But then comes writing tests... writing tests for code that's already there is supremely boring. | ||
| + | |||
| + | ## How do I use it? | ||
| + | |||
| + | ``` | ||
| + | TEST_CASE() { | ||
| + | REQUIRE(vec.add); | ||
| + | } | ||
| + | ``` | ||
| + | |||
| + | A common mistake is " | ||
| + | |||
| + | Think of it this way -- a test should be like a field sobriety test; not an interrogation room. You're supposed to check if a class is " | ||
| + | |||
| + | ## When do I use it? | ||
| + | |||
| + | ## When do I avoid it? | ||
| + | |||
| + | ## Criticism | ||
| + | |||
| + | |||
| + | |||
| + | |||
