(Quick Tips 1) What are unit tests, anyway?
There’s some confusion about what makes a test a unit test. Many people try to focus on the “unit” part of the name, thinking it describes testing a unit of production code. I’ll continue to use the term because it’s widespread, but let’s forget about asking “What’s a unit?” Instead, here’s my definition:
Unit tests are a subset of automated tests where the feedback is quick, consistent, and unambiguous.
Quick:A single unit test should complete in milliseconds. We want thousands of such tests.
Consistent:Given the same code, a unit test should report the same results. The order of test execution shouldn’t matter. Global state shouldn’t matter.
Unambiguous:A failing unit test should clearly report the problem it detected.
…Excerpt from chapter 1 of my book, iOS Unit Testing by Example: XCTest Tips and Techniques with Swift. In Quick Tip 2, you’ll see a technique I call Test Zero.
Since different people mean different things when they say “unit tests,” some avoid the problem by calling them “microtests.”
Have a question or comment about this Quick Tip? Feel free to reply directly to this email.
(If you don't want any more Quick Tips but still want my newsletter, click “Update preferences” below.)
You received this email because you signed up on https://qualitycoding.org.