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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.zipand extract theMolessolution folder.Build the
NUnitproject in Visual Studio (2008) for Release.Copy the output files
Microsoft.Moles.NUnit.dllandMicrosoft.Moles.NUnit.xmlfrom...\Moles\NUnit\bin\Release\toC:\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.dllyou just copied.In your VS test class, mark a test method with the
[Moled]attribute (this will require anusing Microsoft.Moles.Framework.NUnit). As an alternative, wrap its implementation within anusing (MolesContext.Create()) { ... }block (this will require anusing 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.