Pex emits traditional unit tests. Pex manages the set of generated tests in order to only keep relevant tests around.
This management involves two aspects:
- Preventing duplicate tests. Currently, when you run Pex, it always explores a program from scratch. Therefore, it might (re-)generate tests it had already generated before. Such tests should not be emitted again.
- Removing tests which have become irrelevant. When the code of program under test changes, the relevant corner cases might change as well. Therefore, previously relevant tests might become irrelevant, and are replaced by new test cases.
Pex' test bookkeeping only works if
- the generated tests are placed in the Pex test assembly (i.e. the assembly which contains the generating PexClass),
- Pex has access to the symbols (.pdb files) and sources for the generated tests, and
- you do not manually edit the generated tests.
How it works
At first, Pex preprocesses existing tests: Pex starts by scanning the assembly containing the pex fixtures (see PexClassAttribute
) for generated tests (it assumes that they are in the same assembly). Generated tests are recognizable from the Test
attribute and PexGeneratedBy
For each test method, it fetches the source code from the symbols/sources. White spaces are trimmed from the source, and the resulting string is the 'hash' key of the generated test. Pex also uses the expected or unexpected
Once this is done, Pex has a dictionary of test 'hashes' that it can use to determine whether a newly generated test already exists. Duplicated tests are reported but not emitted since they are already present.
If a previously existing test case is not regenerated, it is deleted, unless you remove the PexGeneratedByAttribute