word = unit test, sentence = integration test

I was trying to explain to a manager the difference between unit testing and integration testing.  I used a few different styles for explaining, but one jumped out at me as “have to blog about that one.”

The Analogy

  • unit tests represent testing a word
  • integration tests represent testing a sentence

Why this works

If you use spell a word wrong, you have no hope of your sentence being correct.  The words are the units.  If you use the words in the wrong order or are missing a word or use the wrong word, your sentence is not correct.

It also shows why both unit tests and integration tests are needed.  With just unit tests you won’t know that “cat my hair ate the” is wrong.  After all the individual units are correct.

With just integration tests, it is a lot more work to know everything is correct.  While it is possible to test the entire sentence in one shot for spelling correctness, it is hard.  As humans we spell check one word at a time even if we don’t realize it.  That’s why “coding is fun” is faster to spell check than “codingisfun”.

Conclusion

Thoughts on this?  I don’t remember reading this idea anywhere, but I may have read it and forgotten it.  If anyone knows where it came from, feel free to post that as a comment.