Pex - Automated Whitebox Testing for .NET : Frequently Asked Questions

Frequently Asked Questions


Could you give me a brief comparison between Pex vs MSTest unit testing?

Think about Pex with VSTS unit testing rather than 'vs'. Pex acts as a plugin for unit test framework by providing parameterized unit tests, but it does not prevent the user from writing 'closed' unit tests.

In fact, in many situations, it will probably more adequate to write a 'closed' unit test rather than a parameterized one.

The following example shows how unit tests and parameterized unit tests can live together in the same test class:

  • a classic unit test
    // no parameters, using 'closed' unit tests
    [TestMethod]
    public void AddMoney() {
         Account account = new Account();
         account.Add(100);
         Assert.IsTrue(account.Amount == 100);
    }

  • a parameterized unit test,
    // adding money, we can write a parameterized unit test here
    [PexMethod]
    public void AddMoney(int amount) {
         Account account = new Account();
         account.Add(amount);
         Assert.IsTrue(account.Amount == amount);
    }

Do you support NUnit, MbUnit and xUnit.net?

Yes, extensions for these test frameworks can be downloaded from the Pex Extensions Project.

Can I mix Unit Tests and Parameterized Unit Tests in the same class?

Yes, both can live in the same class. In fact, that is what happends when Pex generates
unit tests.

[TestClass]
class Test {
    [PexMethod] void Foo(int i) {... }
    [TestMethod] void Bar() { ... }
}

Is this a random test generation tool?

No, Pex uses a constraint solver to generate new test inputs.

Is this a test stub generation tool like the MSTest Unit Test Wizard in Visual Studio?

No, from a parameterized unit test written by the user, Pex generates unit tests that call back that test.
In other words, Pex generates test inputs. See example above.

Pex also comes with a Wizard that can generate parameterized test stubs, but they are meant as a boiler
plate starting point, just like the Visual Studio unit test wizard.

Does Pex work with TypeMock?

Currently Pex and TypeMock do not work together.

Do I need to use the PexClassAttribute?

No, the PexClassAttribute is optional. It can be used to specify additional settings for Pex, such as the Test To Code Binding.


How do I load a Pex report in Visual Studio?

When you have run Pex from the command line, you can load the results in Visual Studio through the Pex Exploration Results view.

  • click on the Import Report icon,
importimage.png
  • locate the report.per file in the report folder and select it

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