Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to use Moles with NUnit. Getting "Moles requires tests to be an instrumented process"

Tags:

nunit

moles

I am trying to use moles with NUnit and am getting the following error "Moles requires tests to be an instrumented process". I am also using Visual NUnit within Visual Studio 2008 to get this working. Any help is welcome.

like image 986
Seth Avatar asked Dec 12 '22 19:12

Seth


1 Answers

This is what I did in order to make Moles work with NUnit:

  1. Grab the archive at C:\Program Files (x86)\Microsoft Moles\Documentation\moles.samples.zip and extract the Moles solution folder.

  2. Build the NUnit project in Visual Studio (2008) for Release.

  3. Copy the output files Microsoft.Moles.NUnit.dll and Microsoft.Moles.NUnit.xml from ...\Moles\NUnit\bin\Release\ to C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\. I suspect that this step of re-compiling the NUnit addin instead of using the one coming from the download & install was the actual solving point.

  4. In your VS test project, make sure you add a reference to the C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\addins\Microsoft.Moles.NUnit.dll you just copied.

  5. In your VS test class, mark a test method with the [Moled] attribute (this will require an using Microsoft.Moles.Framework.NUnit). As an alternative, wrap its implementation within an using (MolesContext.Create()) { ... } block (this will require an using Microsoft.Moles.Framework).

  6. From the command line, invoke NUnit test runner through the moles runner with the following: "C:\Program Files (x86)\Microsoft Moles\bin\moles.runner.exe" "path\to\your\test\assembly.dll" /r:"C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\nunit-console.exe" /x86 /args:"/domain=None"

I found that [Moled] attribute does not work with [TestCase(...)] and it brings you back to the uninstrumented error scenario. Instead the using (MolesContext.Create()) block works in that case too.

Once you find that everything works, you might consider running moles runner as an external tool within Visual Studio. Follows instructions in Running Moles using NUnit Console from Visual Studio, updating the arguments as in step 6.

Please note that this was on a Windows 7 64bit machine, with NUnit 2.5.9, Microsoft Pex and Moles (x86) 0.94.51006.1. Consider your actual folders for different paths, versions, etc.

like image 89
superjos Avatar answered Jun 15 '23 06:06

superjos