One of the problem with Pex is that.... it's yet another dependency in your test project. Pex has it's own attributes which makes it very difficult to 'strip it out' of the test source. Many teams won't allow to check-in assemblies, they won't install external components on the build machine and just forget about touching the source code!
So how do you strip Pex?
In "Condition" lies the answer
An elegant solution uses a bit of Reflection, CodeDom and the MSBuild Condition attribute: generate Attribute stubs (shadows) and bind them to the project.
Pex modifies the project file and uses MSBuild conditions to conditionally include files and assembly references in the generated test project.
<Project DefaultTargets="Build" ...> <PropertyGroup> ... <PexShadows>true</PexShadows> </PropertyGroup>
<Reference Include="Microsoft.Pex.Framework" Condition="$(PexShadows) != 'true'" />
when the property PexShadows evalutes to true, the Microsoft.Pex.Framework assembly is not referenced anymore.
<Compile Include="Properties\PexAttributes.cs" Condition="$(PexShadows) == 'true'"> <AutoGen>True</AutoGen> <DependentUpon>AssemblyInfo.cs</DependentUpon> </Compile>
That's it! Flip the value of PexShadows to bind/unbing your test project from Pex.
So what does Visual Studio says ?
Visual Studio is totally fooled by the maneuver. It shows the conditional files and references as if nothing happened. Add a menu item in the project context menu to switch it on and off and we are good to go :)
Page rendered at Sunday, September 07, 2008 8:44:44 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.