Naming Unit Tests

Paul Gielens over on the ASP.NET weblogs has recent post talking about naming patterns for unit tests. He mentions the following naming pattern:

  1. Context
  2. Stimulus
  3. Result

That sounds awfully familiar to what we’ve been taught to use on my current project:

  1. Setup
  2. Execute
  3. Verify

Each test has one method (or system) under test, which is the “execute” step noted above. We test this method once, after we’ve written our setup, and then we verify the results are as expected. Our test names always contain the execute step, and then we’ll usually have a quick little description after that to describe how a test is different from another (the setup):

		public void testSearchUsersByName_NameIsNull()
	

I much prefer our naming to “Context, Stimulus, Result”. That sounds more like the scientific process the skinny grey aliens use when they probe us. I don’t really know that, but I’m just saying…