Pex Issue : "Delete Generated Unit Tests in Class" or Using existing test projects
To give a brief overview of what Pex is,
Microsoft Pex is a Visual Studio add-in that provides runtime code analysis for .NET code. With just a few mouse clicks, you can explore code-under-test to understand input/output behavior in the code, save automated tests that increase your confidence that your code cannot crash—or point to errors that do cause crashes and write powerful parameterized unit tests and generate suites of tests that ensure the code-under-test behaves as intended. If you are a developer writing code, you should be testing it with Pex. More tutorials here.
This post aims at providing a solution to two of the issues that I have come across.
Issue 1: The Pex context menu only has the entry "Delete Generated Unit Tests in Class" and not the usual "Create parameterized unit tests"
Solution: ThePex assemblies should be referenced only in the test project and not in the source projects. For example in my case, the source project that contained the original class on which tests had to be run contained references to “Microsoft.Pex.Framework” & "Microsoft.VisualStudio.QualityTools.UnitTestFramework”. Once I removed the references, I had the “Create parameterized unit tests” menu back.
Issue 2: You already have an existing unit test project. But Pex is not allowing you to select the existing test project as output.
Solution: To your test project, add a reference to the assembly "Microsoft.Pex.Framework” and try again.
If that doesn’t work, follow the steps.
Update your existing test project:
- Run 'Create Parameterized Unit Tests' on your project
- Let Pex create a new project
- Copy the PexAssemblyInfo.cs file (under \Properties) from the generated project into your original test project
- Delete the test project that Pex generated
At this point, the bindings should work. The next time you try to run 'Create Parmeterized Unit Tests' from your types, it should automatically suggest to use your test project.
Important Note on Pex download: Pex comes along with Moles which is a mocking framework. Starting Visual Studio 2012, moles has been integrated as "Fakes". They are not backward compactible. Hence if you would like to use a mocking framework, its is recommended that you have a look at "Fakes".