In the previous post, we went through the exploration testing process to exercise a simple method, CheckPositive. In this post, we'll try the same exploration testing, but will let Pex do it.
// mehod under test1 void CheckPositive(int i, bool @throw) {2 if (i < 0) { 3 Console.WriteLine("not ok");4 if (@throw)5 throw new ArgumentException();6 }7 else 8 Console.WriteLine("ok");9 } // hand-crafted unit tests[TestMethod] void Zero() { CheckPositive(0, false);}[TestMethod] void MinusOne() { CheckPositive(-1, false);}[TestMethod] void MinusOneAndThrow() { CheckPositive(-1, true);}
Exploration testing with Pex
To let Pex explore the CheckPositive, we write a little test wrapper around that method:
[TestClass, PexClass]public partial class ExplorationTesting { [PexMethod] public void Test(int i, bool @throw) { CheckPositive(i, @throw); }
We also instrumented the original method with additional methods to track down the path conditions that Pex computes along the execution traces. Pex generates 3 pairs of values which are equivalent to what the test we manually created:
Page rendered at Monday, October 13, 2008 11:50:33 AM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.