1. It's important to understand why we write unit tests, however, as well as the strategies developers employ when designing unit tests.
  2. Add a test. Run all of your tests and observe the new test failing. Implement the code. Run all of your tests and observe the new test succeeding. Refactor the code.
  3. There's a twofold purpose to writing tests before writing your code. First, it forces you to think about the business problem you are trying to solve. For example, how should successful scenarios behave? What conditions should fail? How should they fail? Second, testing first gives you more confidence in your tests. Whenever I write tests after writing code, I always have to break them to ensure that they are actually catching errors. Writing tests first avoids this extra step.

출처: 까먹어버림