Writing Tests First with Comments

Clarify intentions before coding.

The Change

Before you write any new code, say what you are going to do with comments as a four-part unit test.

The Value Proposition

Every developer learns to write code. However, often we start with a set of tests already written for us. It can be harder to learn to write those tests than it was to learn to write code that passes them!

The hard part is that writing a test requires you to clearly state your intention. You need to break the problem down and describe one aspect of your goal. You also need to express that goal in code. Writing tests first with comments allows your to separate these two parts of your thinking. First you will define the goal, then later you will express it in code. This gives several advantages.

  1. It is much easier to write the tests.
  2. Each test is easier to make pass.
  3. The tests are easier to read by other team members.
Please log in

This content is only available to students. Please log in to access it.