GOTCHA: Unit testing – Make your values unique

We recently discovered a bug in our code where there is actually a unit test exercising the code. To use the parlance of the Scientific Method, the problem was that our controls (constants) had the same value so, though you can test the predicted outcome, you have low falsifiability.
 
A simplified illustration:
Problem:
int employeeId = 3;
int employerId = 3;
 
GetValueByEmployeeId(employeeId);
GetValueByEmployerId(employerId);

Under the hood, they could be doing the exact same thing that returns the expected value. This gives you the low falsfiability. If you make your values unique, you could better identify that the values you passing in are behaving (returning) as you intend.

Resolution:
Make your controls unique.
 
int employeeId = 3;
int employerId = 5;
 
GetValueByEmployeeId(employeeId);
GetValueByEmployerId(employerId);
 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s