Steven Evers
Steven Evers

Reputation: 17196

Pex not satisfying code contract

I'm trying to wrote a pex test, and I noticed that it always was feeding a false value as one of the params that I wanted. My test looked like this (simplified: there are/were more params, but otherwise no different):

[PexMethod]
public void TestCtor(bool value)
{
    ArbitraryType myType = new ArbitraryType(value);
}

I wanted to test a scenario where I would have pex do the exploration, ensuring that value would be true. I made another test that looked like this:

[PexMethod]
public void TestCtor(bool value)
{
    Contract.Requires(value == true);

    ArbitraryType myType = new ArbitraryType(value);
}

But when I have Pex explore that, it still spits in false to value and the test it generates "passes". If I put a line after the requirement saying Contract.Assert(!value); It'll create another test and pass true for value to fail the assertion.

The question is, why isn't Pex satisfying the code contract?

Upvotes: 0

Views: 127

Answers (1)

porges
porges

Reputation: 30580

I'm not sure what Pex is going to do with Contracts in the test methods, but I can't see it being a Good Thing :)

If you want Pex to do this, the correct thing to do is use PexAssume.IsTrue(value).

Upvotes: 1

Related Questions