DEV Community

Oyetoke Toby
Oyetoke Toby

Posted on

How Well Do You Write Tests?

I spend almost the same amount of time writing code to write tests. But I noticed that reduced a lot when working on static type languages.

What do you think? How well do you write tests?

Top comments (1)

Collapse
 
lukegarrigan profile image
Luke Garrigan

I follow uncle bobs rules for writing tests; the 3 laws of TDD:

  1. You are not allowed to write any production code unless it is to make a failing unit test pass.
  2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
  3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.

Also, you said "I noticed that reduced a lot when working on static type languages." When writing tests in dynamically typed languages you shouldn't be testing for types so really you should be writing an equivalent amount of tests. But I know this goes on, I've seen countless applications where people have written tests in dynamically typed languages like: "What happens if I put a string in here? ahh okay, now what happens if I put an int in here", this shouldn't happen.