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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
We are looking at Mock object frameworks for our net developement. TypeMock looks interesting on paper but I am having a lot of trouble evaluating its utility.

We use nant to do our builds (and the unit2 task to run our tests). In addition, we are using Clover.Net to process coverage. First, it seems that adding TypeMock would break all our Nant build scripts as we would have to process nunit and clover using a different stategy :cry: . Do you have any plans for a better solution to these problems.

I have downloaded TypeMock marked as 3.1.0.0. and I am using the .NET framework 1.1. We are using nant-0.85-rc2. I have installed the standard DEMO license to enable the use of nant tests.

I am using a simple project to evaluate TypeMock so currently I have a single class being tested with two tests. I am more or less following the documentation. I initialize the MockManager as the first thing in my test and Verify as the last.

Everytime I run my tests the TypeMockStop task throws... I doubt that this is what is suppose to happen:

System.IO.FileNotFoundException: File or assembly name Configuration, or one of its dependencies, was not found.
Nom du fichier : "Configuration"
at TypeMock.NAntBuild.TypeMockStopTask.ExecuteTask()
at NAnt.Core.Task.Execute()
at NAnt.Core.Target.Execute()
at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies)
at NAnt.Core.Project.Execute()
at NAnt.Core.Project.Run()

In my tests, I create a single MockObject in each test, but I still get a message that my license only allows me to create a single mock... is this the intended behavior (i.e. 1 mock object created per nunit run). If so, I would say that there is little chance that I will be able to effectively evaluate this product.

Finally as I am writing my tests before my implementation the method on my mock that I expect to be called (ExpectCall()) is never called. I would expect this to be verified when I call the Verify method - but it does not seem to be. If I call GetCallCount() on the target method I can see that it is never called however.

Do you have any comments on these problems?
asked by sellingerd (5.7k points)

6 Answers

0 votes
unit2 task to run our tests...Do you have any plans for a better solution to these problems.

One way is to run the nant command via TMockRunner
example:
TMockRunner nant.exe ...


Everytime I run my tests the TypeMockStop task throws... I doubt that this is what is suppose to happen:
System.IO.FileNotFoundException: File or assembly name Configuration, or

This is a known bug and will be solved in the next patch release (Due Next Week).
A workaround is to copy Program_FilesTypeMock.NETTypeMock.NETPrivateAssembliesConfiguration.dll
to
Program FilesTypeMock.NETTypeMock.NET

my license only allows me to create a single mock... is this the intended behavior (i.e. 1 mock object created per nunit run). If so, I would say that there is little chance that I will be able to effectively evaluate this product.
This is expected :?
I would be happy to send you a fully functional evaluation license. Please send a note to sales@typemock.com

I would expect this to be verified when I call the Verify method - but it does not seem to be.
I tried a simple example and it works as expected. Please send me the example.
Here is my example:
[Test]
        public void Bug210()
        {
            Mock m = MockManager.Mock(typeof(TestedClass));
            m.ExpectCall("SomeVoidMethod");
            TestedClass t = new TestedClass();
            MockManager.Verify();
        }

When running I get:
TestCase 'TestUsingTypeMock.Bug210'
failed: TypeMock.VerifyException : 
TypeMock Verification: Method TestedClass.SomeVoidMethod() has 1 more expected calls

   at TypeMock.MockManager.Verify()
   Bug210.cs: at TestUsingTypeMock.Bug210()
answered by scott (32k points)
0 votes
Thanks for the speedy reply. I am going to try running with TMockRunner.

As for the my problem with my method not verifying, the problem is on a MockObject, not a Mock. This test fails on my installation

  [Test]
  public void TestDoNotCallMockObjectMember () {
    MockManager.Init ();
    MockObject msMock = MockManager.MockObject (typeof (IMailSender));
    msMock.ExpectCall ("Send", 1, new Type[] { typeof (string), typeof (string) });
    IMailSender ms = msMock.Object as IMailSender;
    if (ms == null) {
      Assert.Fail ("Can not mock the mail sender");
    }
    try {
      msMock.Verify();
      Assert.Fail ("should never reach this code");
    } catch (TypeMockException) {
    // this is okay
    }
  }



When I execute this test, I get an NUnit.Assertion exception and not the TypeMockException that I was hoping for.

Thanks in advance for any help.

d.
answered by sellingerd (5.7k points)
0 votes
d.

Please send IMailSender

BTW It is much nicer to write
msMock.ExpectCall("Send", 1,typeof(string), typeof(string));
answered by scott (32k points)
0 votes
Okay, IMailSender is quite simple:

namespace Vigis.Util {

  using System.Collections;

  public interface IMailSender {
    void Initialize (string host, ArrayList toAddresses, string fromAddress);
    void Send (string subject, string message);
  }
}


I tried the DLL that you sent. I added it to the GAC and I used it to build my application ... My assembly manifest contains this reference to TypeMock (I am not sure I am building and running against the correct typemock assembly).

.assembly extern TypeMock
{
.publickeytoken = (3D AE 46 00 33 B8 D8 E2 ) // =.F.3...
.ver 3:1:2:0
}


Unfortunately the my execution does not seem to work as the test crashes when I initialize the MockManager:

[exec] NUnit version 2.2.0
[exec] Copyright (C) 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole.
[exec] Copyright (C) 2000-2003 Philip Craig.
[exec] All Rights Reserved.
[exec]
[exec] OS Version: Microsoft Windows NT 5.1.2600.0 .NET Version: 1.1.4322.2032
[exec]
[exec] .F
[exec] Tests run: 1, Failures: 1, Not run: 0, Time: 0.1093715 seconds
[exec]
[exec] Failures:
[exec] 1) Vigis.Vtp.Test.TestTransactionFileWatcher.TestDoNotCallMockObjectMember : System.NullReferenceException : La référence d'objet n'est pas définie à une instance d'un objet.
[exec] at al.f()
[exec] at TypeMock.MockManager.Init(Boolean collectAllCalls)
[exec] at TypeMock.MockManager.Init()
[exec] at Vigis.Vtp.Test.TestTransactionFileWatcher.TestDoNotCallMockObjectMember() in c:devGFC4VtpWatcherServiceTestTransactionFileWatcher.cs:line 91
[exec]
[exec]
[exec] C:devGFC4VtpWatcherServiceuild.xml(57,4):
[exec] External Program Failed: V:devigis oolsNUnit2.2in unit-console.exe (return code was 1)


The referenced line is where I call the MockManager.Init() method.

:?

d.
answered by sellingerd (5.7k points)
0 votes
Ok,
Now that I see your code here is the answer:
Revert back to the old dll (if you don't have it reinstall TypeMock)
Change the test code to:
msMock.ExpectCall("Send");


The other arguments are for Generic Methods.

The bug you found happens for Generic Methods eg.
void Send<A,B>(A subject, B message);
answered by scott (32k points)
0 votes
Okay Thanks,
answered by sellingerd (5.7k points)
...