You’re unit testing, right? …. right? (If not… shame on you… ) It’s known that TDD/nDD types of development dramatically increase the ability to refactor with confidence, increase code readability and help define and enforce business rules (in the tests). Unit testing helps with TONS of things in development (literally the list could go on and on), but what about the unit test names? What do those do for us as developers?
Predecessors In The Name Game
Roy Osherove has a good post on Unit Test names. Jean-Paul also has tons of good info about unit test names on his blog. I tend to follow these same guidelines. Also – awhile back on the altnet list there was a thread which spawned this post, but unfortunately I could not find it. If I do run across the post I’ll augment this thread with the link.
Background
But what about when a bug report comes in? In my work I’ve used an alternative method so I thought I’d post it here.
- Lets say the bug report says that "CalculatePayment" is returning the wrong value when the system is in a certain state. This kind of test was completely missed during development. Heck, it happens! Your task is to implement a solution for this bug.
- Most likely you’re going to write a unit test to assert that the solution you specified has been implemented as expected.
Naming Convention
When naming these unit tests I will add the word FIX_<WorkItemNumber>_<MethodName>_<StateUnderTest>_<ExpectedBehavior>() as the method name.
Example:
FIX_186_CalculatePayment_WhenRateLessThan1000_ThrowPaymentException() { ... }
From this test fixture name I can glean that this is a fix for bug 186, for the CalculatePayment method, for the state when a rate is less than 1000, the method should throw an exception. I’ve now documented my code as well as created a very readable and understandable unit test name.
I know this is not something everyone wants to do or would do, but in certain companies I’ve worked at this has helped with work item issue resolution and tracking.
Leave a Reply
You must be logged in to post a comment.