TypeMock 6.0.4.0 behaves differently on different boxes

411 Views Asked by At

Help!

This code works fine on my local VS2010 with TypeMock, however fails on our build server, when ran through NCover.

My code:

 using (RecordExpectations expect = RecorderManager.StartRecording())
    {
74:             RequestDataLayer.GetAllUsers();
75:             expect.Return(DatabaseUsers);
                // other definitions to follow
    }

Yields this error on a CruiseControl.Net environment:

Execute
TypeMock.TypeMockException: 
*** Cannot use Return in this sequence, there must be a mocked statement first
Perhaps you are trying to mock a method from mscorlib
   at TypeMock.RecordExpectations.b(String A_0)
   at TypeMock.RecordExpectations.a(String A_0)
   at TypeMock.RecordExpectations.Return(Object returnValue)
   at Request.UserSyncTest.SyncData() in UserSyncTest.cs:line 75

The source for the method I try to mock is:

public class RequestDataLayer
{
        public static User[] GetAllUsers()
        {
            // some LINQ magic to get users out of DB, then a .ToArray()
            // returns an object array
        }
}

So there isn't anything special to it, apart from the fact the method is static. Since then I refactored the method to make it nonstatic, effects on the bottom of this page.

I had a similar issue previously, this was to do with exploiting the Isolate<> syntax of TypeMock, I ran into the same scenario, of tests working fine locally (through Gallio test runner), but failing on the build server (CC.Net, Gallio, TypeMock, NCover).

I'm running 6.0.4.0 of TypeMock on both dev and build boxes.

Also, what seems to have worked was moving lines 74 and 75 down in the RecordExpectations block - the error didn't show, BUT the method call simply wasn't mocked silently.

Ideas welcome.

3

There are 3 best solutions below

0
On BEST ANSWER

OK, we found out what the problem was - embarassingly enough TypeMock wasn't properly called through the NAnt script.

This is still a mystery however why we didn't simply see the "TypeMock" is not enabled error message, but this weird behaviour instead.

2
On

Disclaimer I work at Typemock.

Are you using the ClearMocks attribute on the test method or test class?
If you are using the attribute and still get the exception please contact our support:
support at typemock.com

3
On

When I see this sort of thing, it's usually:

  • Test ordering - the tests run in one order on the dev box but a different order on the build box, which uncovers issues like some fixtures not properly cleaning up after themselves.
  • Environment differences - things like the dev environment running a 32-bit build but the build server running a 64-bit build.

There is a troubleshooting guide for these hard-to-figure-out issues on my blog. Try running through that and see if any of them look like they might help you out.

I will say this: It is sometimes a long and painful process to figure out which fixture is causing the problem. I have gone all the way to the point of removing all fixtures from the unit test assembly and adding them back, one at a time, until the problem resurfaces. You will potentially have to be a little patient.

If you have the option, upgrade to the latest version. With every release, Typemock gets better and better about these odd issues and the problem may rectify itself with a later release.