Relationship Between the Test Name and Test in TDD

The relationship between the test name and the implementation of the test must be consistent. We want to avoid code like this:

it 'Dog should wag the tail when it sees the owner' do
  owner = Person.new
  dog = Dog.new
  result = dog.see(owner)

  assert_equal 'bark', result
end

This example seems obvious but developers make this very common mistake. We can fix this code as follows:

it 'Dog should wag the tail when it sees the owner' do
  owner = Person.new
  dog = Dog.new
  result = dog.see(owner)

  assert_equal 'wagging my tail', result
end

The mistake is often caused by lack of knowledge about the domain because the developer is unfamiliar with the domain. So, instead of blindly adding new tests, during the refactoring step - we must review the existing tests and make decisions about deleting or updating the tests to reflect our growing knowledge about the domain. By doing so, we as developers make the transition from Me Milk to Please give me some milk to drink.

A test must be syntactically and semantically correct. Ruby interpreter enforces the syntactic correctness of a test. It is the developer's responsibility to enforce the semantic correctness of a test.

I discuss this in depth in my upcoming TDD in Ruby book scheduled for release in March 2017 by Apress. Subscribe to my newsletter if you want to be notified about the discount coupon codes for the upcoming book.


Related Articles


Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.