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
Call to a static getting through.

Not sure if I am missing something...

Trying to Mock a public static call. I call MockManager.Init() right at the start of main so I know this class it not being using before the call to MockManager.Init(). In the tracer the call expectation that is not met can be seen but there is also an unexpected call to the same method! This method is not overloaded.

The setup is:

TypeMock.Mock exceptionReporterMock =
TypeMock.MockManager.MockAll(typeof(UnhandledExceptionManager, TypeMock.Constructor.NotMocked));
exceptionReporterMock.ExpectCall("ReportException");
asked by servotest bob (3.8k points)

9 Answers

0 votes
Hi
Please try changing ExpectCall to AlwaysExpect and see what happens.

Also could you send me the definition line of UnhandledExceptionManager.ReportException
answered by scott (32k points)
0 votes
Thanks,

It's the same when I change it to ExpectAlways.

Typemock v3.1.3.0. .Net v1.1.

signature: public static void ReportException(object source, Exception ex) {
answered by servotest bob (3.8k points)
0 votes
Could you send me an example? and the trace?
answered by scott (32k points)
0 votes
How do I get the trace?

Not sure how to send you an example. I guess I could try and create a little vs project add a method with the same signature and hope the same behaviour is seen. I also have a couple of other places where I am having problems with calls / constructor calls not being intercepted. In both cases they are intercepted when using .Net 1.1 but not with .Net 2.0.
answered by servotest bob (3.8k points)
0 votes
How do I get the trace?

Run TypeMock Tracer before running the tests

In both cases they are intercepted when using .Net 1.1 but not with .Net 2.0.

Interesting, so if you run the same dll, with target=1.1 it works?
(use TMockRunner -target=1.1 ....).

How are you runing your tests? MsBuild TMockRunner? NAnt? Visual Studio?
answered by scott (32k points)
0 votes
We have our own test runner written using the NUnit framework. We compile the tests into an assembly and then they are passed to our test runner application which loads the assembly using Assembly.LoadFrom. We run our test runner though TMockRunner. In most cases TypeMock works for us.

I have just tried running the tests in question through the nunit gui runner and they work fine! I'm not sure what we could be doing in our testunner to interfere with typemock beahviour. I just tried using Assembly.Load and Assembly.LoadFile to load the dll containing the tests but still get the problem.

Any ideas?

In answer to your questions:

I'm not sure what Tracer output you want me to cut and paste. I described what the Tracer was indicating about the methods in question in the original email.

The problem I have with the method that works in 1.1 but not 2.0 is a different one from the original I posted about, although it is similarly about a method call not being intercepted when I exepct it to be. It works when I compile our test classes using version 1.1 of the .Net compiler. The call doesn't get intercepted when I compile our test classes using version 2.0 of the .Net compiler.
answered by servotest bob (3.8k points)
0 votes
Could you please run with the logging enabled and send me the TypeMock log files?
answered by scott (32k points)
0 votes
sent
answered by servotest bob (3.8k points)
0 votes
Hi,
Part of the problem is with the way that .NET compiles static members, when a static member is in the same assembly as the tests, the method might not be called.
This should be solved when using standard testing frameworks, but might appear when using proprietary testing frameworks.
answered by scott (32k points)
...