Writing a unit test for a singleton implementation

Diggory diggsey at googlemail.com
Fri May 17 14:06:26 PDT 2013


I think we all understand it's not going to catch every race 
condition, or even a given race condition every time, ie. it 
can't prove that the code is correct.

What it can do however is prove that code is incorrect. If the 
unit test fails there is definitely something wrong with the 
code, therefore it's a useful test to have.

The most obvious case is if there is a change to the singleton 
code which accidentally creates a race condition. Any chance of 
detecting that in a unit test is better than no chance of 
detecting it.


More information about the Digitalmars-d mailing list