This is a general recommendation if you're planning to use a tool like Pex in the future: make sure that preconditions (i.e. parameter validation) fails in a different fashion that other assertions.
Here's a snippet that shows the problem:
// don't do thisvoid Clone(ICloneable o) { Debug.Assert(o != null); // pre-condition ... object clone = o.Clone(); Debug.Assert(clone); // assertion}
Why is this bad?
A tool like Pex will explore your code and try to trigger every Debug.Assert it finds on its way. When the assertion is a precondition, it is likely expected and one would like to emit a negative test case (i.e. 'expected exception').
The problem in the snippet above is that both failure will yield to the same assertion exception and it will very difficult to *automatically* triage the failure as expected or not.
How do I fix this?
Make sure different classes of assertions can be differentiated automatically, through different exception types, tags in the message, etc...
Page rendered at Saturday, July 04, 2009 6:21:27 AM (Pacific Daylight Time, UTC-07:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.