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.
This is what I did in order to make Moles work with NUnit:
Grab the archive at C:\Program Files (x86)\Microsoft Moles\Documentation\moles.samples.zip
and extract the Moles
solution folder.
Build the NUnit
project in Visual Studio (2008) for Release.
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.
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.
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
).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With