Pex - Automated Whitebox Testing for .NET : Freezing Current Behavior for Future Regression Testing

Saving Current Behavior For Future Regression Testing


When a parameterized unit test returns a value, Pex explores the value public property graph and saves the current value as assertions in the generated test. When replaying the test, the assertion will ensure that the observable behavior has not changed.

[TestClass, PexClass]
public partial class CalendarTest {   
    [PexMethod]
    public string GetMonth(int i) {
        string month = Calendar.GetMonthName(i);
        // storing output, giving it a name
        return month;
    }
}

The resulting generated test call will contain code to ensure that the month names returned by GetMonthName do not change in the future.
Internally, Pex asserts that the value previously associated with the name "month" is equal to "January".

[TestMethod]
public void GetMonth01() {
    // invoke parameterized unit test, which associates names to computed values
    string result = GetMonth(1);
    // verifying that we received the expected named value
    // we expect "January", because that was the value Pex saw when generating this test
    Assert.AreEqual("January", result); 
}
...

(c) Microsoft Corporation. All rights reserved. pex Wiki Documentation 0.93.50813.0