chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I recently purchased TypeMock and the TypeMock examples seem to run fine. However, since yesterday, I have been unable to get even the simplest TypeMock test to run (although, inexplicably, the TypeMock examples continue to run just fine).

I am mocking my own simple class, not framework ones. I get the same error running the test from VS2005 and TMockRunner. To be honest, I feel like I am going mad, very quickly. I assume that I must be making a rookie mistake, I just can't see where.

XP Pro SP2, Dual CPU, Dual monitor, 3Gb RAM. VS 2005 Pro SP1, R# 2.5.1.

So, from scratch:

  • I create a new C# class library project using VS2005 Pro SP1 (with R# 2.5.1)
  • I add references to nunit (2.2.8) and TypeMock (3.6.1 Enterprise)
  • I add two classes, the tester and the testee. Both very simple and reproduced below
  • I run the tests from VS2005 (TypeMock.NET is enabled) using either TestRunner or R# Test tool OR I run the test using TMockRunner.exe, as shown below
  • I get an error

I have tried rebooting, unitstalling and reinstalling TypeMock. All to no avail.

TMockRunner output with Error

C:DevTypeMockBrandNewTestTypeMockBrandNewTestinDebug>"c:Program FilesTypeMockTypeMock.NETTMockRunner.exe" "c:Program FilesNUnit-Net-2.0 2.2.8in
unit-console.exe" TypeMockBrandNewTest.dll
NUnit version 2.2.8
Copyright (C) 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole.
Copyright (C) 2000-2003 Philip Craig.
All Rights Reserved.

OS Version: Microsoft Windows NT 5.1.2600 Service Pack 2    .NET Version: 2.0.50727.42

Tests run: 1, Failures: 1, Not run: 0, Time: 0.313 seconds

1) TypeMockBrandNewTest.Class1.RunMe : TypeMock.TypeMockException :
*** Cannot use Return in this sequence, there must be a mocked statement first
   at TypeMock.RecordExpectations.b(String A_0)
   at TypeMock.RecordExpectations.a(String A_0)
   at TypeMock.RecordExpectations.Return(Object returnValue)
   at TypeMockBrandNewTest.Class1.RunMe() in c:DevTypeMockBrandNewTestTypeMockBrandNewTestClass1.cs:line 15

Tester class
using NUnit.Framework;
using TypeMock;

namespace TypeMockBrandNewTest
   [TestFixture] public class Class1
      [Test] public void RunMe()
         using (RecordExpectations recorder = new RecordExpectations())
            Boo boo = new Boo();
            recorder.Return(22); // NOTE: THIS IS LINE 15 INDICATED IN THE ERROR OUTPUT

         Boo b = new Boo();
         Assert.AreEqual(22, b.GetValue("foo"));

Testee class
namespace TypeMockBrandNewTest
   public class Boo
      public int GetValue(string arg)
         if (arg == "boo") return 1;
         return 2;

I have the output from running after set TMOCK_VERBOSE=1 but I am not sure that I can attach those files to this post.

!!!!P L E A S E H E L P!!!![/i]
asked by hebbja (1.2k points)

2 Answers

0 votes
Welcome to the Forums.
Your problem is very strange. I have tried in on my machine and it works like a charm. (By the way you have a cool machine!!)

... I found the problem. TypeMock does not mock any types from ASSEMBLIES that start with TypeMock.

Sorry about this, We should really change this, or at least warn about it.
Just change your library name and then it will work.
answered by scott (32k points)
0 votes
Thank you, Thank you, Thank you. I really thought I was going mad. Especially when I could swap some identical source code between your example and my test and still see the example assembly running and my test still failing!!

Now I can get on and post my real problem that I am having with TypeMock. Hopefully you can fix that too... :D
answered by hebbja (1.2k points)