DAY 17
πΒ μ€λ μ½μ λ²μ : 9μ₯ ~ Clean Tests
<aside>
π μ±
μμ κΈ°μ΅νκ³ μΆμ λ΄μ©μ μ¨λ³΄μΈμ.
</aside>
- The Three Laws of TDD:
- First Law You may not write production code util you have written a failing unit test.
- Second Law You may not write more of a unit test than is sufficient to fail, and not compiling is failing
- Third Law You may not write more production code than is sufficient to pass the currently failing test
- ...having dirty tests is equivalent to, if not worse than, having no tests. The problem is that tests must change as the production code evolves. The dirtier the tests, the harder they are to change.
- As you modify the production code, old tests start to fail, and the mess in the test code makes it hard to get those tests to pass again. So the tests become viewed as an ever-increasing liability.
- Test code is just as important as production code. It is not a second-class citizen. It requires thought, design, and care. It must be kept as clean as production code.
- It is unit tests that keep our code flexible, maintainable, and reusable.
- Readability is perhaps even more important in unit tests than it is in production code. What makes tests readable? The same thing that makes all code readable: clarity, simplicity, and density of expression. In a test you want to say a lot with as few expressions as possible.
<aside>
π€ μ€λ μ½μ μκ°μ? λ μ€λ₯΄λ μκ°μ κ°λ³κ² μ μ΄λ³΄μΈμ
</aside>
βThese three laws lock you into a cycle that is perhaps thirty seconds long.β
You gotta be kidding me! I can spend an entire day trying to write tests or fix broken tests.
<aside>
π κΆκΈν λ΄μ©μ΄ μκ±°λ, μ μ΄ν΄λμ§ μλ λ΄μ©μ΄ μλ€λ©΄ μ μ΄λ³΄μΈμ.
</aside>
- Iβm a front end developer. I wonder if thereβs a difference in test code between frontend and backend.
<aside>
π‘ μκ° 3μ€ μμ½
</aside>
- I feel a lot more encouraged to write TDD now. I always write tests after I finish writing the production code. (Iβm only starting to get the habit of writing tests for my code now) Iβm glad that my company encourages to write tests because I remember interviewing a company before where one of the devs said that βtests are just a waste of timeβ (but this company is an agency, so understandable)
- Test code is just as important as production code. It is not a second-class citizen. It requires thought, design, and care.
- What makes tests readable: clarity, simplicity, and density of expression.