Question

We are using Moles to test some of our legacy code. Currently all of our unit tests pass when run locally using either MSTest or Resharper's test runner. However when run on the build server (we use a slightly modified TFS 2010 Workflow, using MSBuild and MSTest) all of our Moles tests fail.

When I looked into the cause it was because when the .Moles.dll were generated on the build server, only the Stubs (classes prefixed with "S") were created but none of the Moles classes (classes prefixed by "M").

Our code still compiles because one of our developers created a Framework for Moles to simplify the syntax, which uses Expressions and Delegates to make working with Moles feel like working with Moq. The framework uses Reflection to get the Moles version of the methods but because the "M" classes are created it throws a NullReferenceException when trying to get the method because the call to Assembly.GetType returns null.

EDIT: The latest version of the Pex & Moles library are installed on the build server.

EDIT 2: Here is the command line that is in the MSBuild Log

"C:\Program Files (x86)\Microsoft Moles\bin\moles.exe" @"D:\Builds\4\DeltaNet\Run All Unit Tests\Sources\DeltaNet\src\DeltaNetTests\obj\Debug\Moles\moles.args"

And the contents of "moles.args"

Common.Logging.moles;DeltaNetUtils.moles;System.configuration.moles /molesfilesonly /referenceassemblies:"<lots-of-dll-files>" /cachepath:"C:\Program Files (x86)\Microsoft Moles\bin\..\MolesAssemblies" /intermediatepath:"D:\Builds\4\DeltaNet\Run All Unit Tests\Sources\DeltaNet\src\DeltaNetTests\obj\Debug\Moles" /outputpath:"D:\Builds\4\DeltaNet\Run All Unit Tests\Sources\DeltaNet\src\DeltaNetTests\MolesAssemblies" /clrversion:v4.0.30319 /targetframeworkversion:v4.0
Was it helpful?

Solution

So, I had another look at this today and I think I came up with the problem and it was depressingly simple.

I was using moles in 2 different test projects and in one of them I specified exactly which classes I wanted the moles for using the assembly.moles xml file. This one must have been compiled after the one with the bulk of my tests and so it overwrote it in the Binaries directory.

I removed the specifics from that file and now it looks like my tests are passing and the MXXX types are being created.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top