This is one problem for which we don't have an elegant solution yet:
what is the best way to craft a name for a generated test?
Let's see an example; given the following parameterized unit test,
[PexMethod] void Test(int i) { if (i == 123) throw ArgumentException();}
Pex would generate 2 tests: i = 0, i = 123. So it seems doable to infer test names such as
[TestMethod] void Test0() { this.Test(0); }[TestMethod, EE(typeof(ArgumentException))]void Test123ThrowsArgumentException() { this.Test(123); }
So what's so difficult about it? Well, most PUT's aren't that simple and as the size of the generated parameter increases, the methods might increase as well (strings getting bigger). Here's a list of potential problems:
Our approach: Timestamps
To the light of all those problems, we've taken the shortcut route in Pex by simply using combination of the parameterized unit test method signature and the timestamp when the test is generated:
[TestMethod] void TestInt32_20080224_124301_35() { ... }
This is ugly, how can I change that?
We've added an extensibility point to support custom test naming scheme. After registering your 'namer', you will get opportunity to craft a test name following your favorite code standard. You will have the generated test, output, exception, etc... at your disposition to make an intelligent choice there.
Off course, you're also welcome to drop a comment on this post to suggest a better scheme.
Page rendered at Sunday, September 07, 2008 10:02:02 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.