C# Unit Testing: How to integrate NUNIT/MBUNIT with Microsoft PEX(Parameterized unit testing). After I have seen few videos of Microsoft PEX, wondering whether I can able to add PEX testing in my NUNIT test project and also want to add them to nightly build. Is that possible?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Yes, it is possible.
We run a pretty ordinary (non-bleeding edge government style) setup with CruiseControl.Net running NAnt running MSBuild, NUnit, Code Contracts, Pex. Tests are generated with the Pex Visual Studio (Professional edition) GUI and then the generated files are checked in to our SVN. There is no extra Pex step on the server but it still runs all the NUnit tests as a normal test suite. Since we are using Code Contracts, the Code Contract post-build step still needs to be run.
When running Pex in Visual Studio to generated parameterized tests, it will let you select what test framework to use. For a new project select NUnit and, when prompted, browse to the folder containing your
nunit.framework.dll
linked to your project.So far (at least until everyone in my department is used to Pex) we've separated hand-written tests from the generated Pex tests by splitting them to two test projects per code project. For example
Product.XYZ
has bothProduct.XYZ.Tests
(ordinary, hand-written NUnit tests) andProduct.XYZ.PexTests
(a fully generated project with only generated tests). In the hand-written tests we write expected (business-case based) input and outcomes, and then use Pex to make sure we're not missing any potentially dangerous pre- or postconditions. Both tests suites are automatically executed on developer machines' ReSharper test runner and the CCNet build server, plus we use both for code coverage checks using OpenCover.Using Pex and Code Contracts without installing them on the build server
Below are some notes that I'm writing while it's fresh. Might be moved or deleted.
Note that it's not necessary to run the installer for neither Pex nor Code Contracts on the build server. This helps if you have stingy sysadmins or projects that might use conflicting versions of Pex or Code Contracts. Moles still has to be installed on the build server, so skip this if using Moles.
Product.XYZ.PexTests
for you. Generate some (only one or two to start with) parameterized Pex method tests as well, and let Pex generate the.g.cs
files with the actual NUnit tests.Microsoft.Pex.Framework.dll
for your solution and re-add theProduct.XYZ.PexTests
project reference for your local copy. Remove your.moles
and references to Moles,Microsoft.ExtendedReflection.dll
,Microsoft.Moles.Framework.dll
.CodeContractsInstallDir
to point to your Code Contracts folder (include a trailing slash) before building (for example in your build script).Microsoft.CodeContracts.targets
(see below) after other<Import />
tags in your code project'sProduct.XYZ.csproj
file.</Project>
your code project'sProduct.XYZ.csproj
(see XML below). You might want to move the check depending on if you have Code Contracts runtime checking enabled only for some builds.Code Contracts build target import
Code Contracts check from userdoc.pdf chapter 5.1.3
cruisecontrol.net nunit pex code-contracts c#-4.0