Homepage | About Me | Testing ASP.net Book | Best Blog Posts | Personal Projects | Follow me on Twitter | GitHub | SlideShare | RSS
Blog.BenHall.me.uk

How to have Pex generate NUnit, MbUnit and XUnit tests

Thursday, August 21, 2008

By default, Pex will generate MSTEST tests, however that doesn't mean you are constrained to using MSTEST for your project. The Pex Extensions project on CodePlex has a set of extensions which allows Pex to generate code for the three main test frameworks. I've just committed some changes to make the code work against the newly released Pex 0.6.  In order to generate tests for a particular framework, you need to follow these instructions.

XUnit

image1) Reference Pex.xUnit.dll

2) In your test project's AssemblyInfo.cs. Add the attribute - [assembly: Pex.Xunit.PexXunitPackage]

3) Pex will now start generating xUnit tests.

NUnit

image 1) Reference Pex.NUnit.dll

2) In your test project's AssemblyInfo.cs. Add the attribute - [assembly: Pex.NUnit.PexNUnitPackage]

3) Pex will now start generating NUnit tests.

MbUnit v3

1) Reference Pex.MbUnit.dll

2) In your test project's AssemblyInfo.cs. Add the attribute - [assembly: Pex.MbUnit.PexMbUnitPackage]

3) Pex will now start generating MbUnit v3 tests. A MbUnit extension is also included within the Gallio\MbUnit package.

Note: At the moment, you need to download the source code from codeplex and compile the binaries yourself, there is a single solution file which will build everything.

image

You also need to ensure both the extensions and your test project are built against the same version of the unit testing framework, otherwise there will be a type mismatch and Pex won't be able to generate any tests.

Technorati Tags: , , ,

Labels:

Blogger comments

At 7:27 PM, Anonymous Reid Hochstedler said...
Sadly it appears that Pex will not generate NUnit 2.5alpha3 tests. Any hope of this in the near future?    
At 8:07 PM, Blogger Ben Hall said...
Pex would be able to generate 2.5 tests, however you will have to do some additional work. The Pex Extensions project will help. The binary releases are built against 2.4.8, however you can manually rebuild the project for 2.5 and then Pex will be able to generate code.

Read this wiki page on how to do it:
http://www.codeplex.com/Pex/Wiki/View.aspx?title=build&referringTitle=Home

Hope this helps, if you want to know anything else please let me know.

Ben    
At 1:14 PM, Anonymous Reid Hochstedler said...
It worked. Thanks for your help.    
At 4:32 AM, OpenID Peli said...
Pex version 0.11 and up supports NUnit, MbUnit and xUnit.net out of the box.