This API is now obsolete.

Since JustMock 2013 Q2 you don`t need to initialize classes or members anymore.

The Initialize method is used for setting up all class methods during test initialization.

You will need to use Mock.Initialize() if method or property is invoked directly before the acutal test method. Otherwise the test will fail, due to the fact, JustMock intercepts or setups concrete methods / properties on demand.

Initializing Classes

Assume that we have the following class:

Now you want to check if one of the methods in Foo is actually been called. This can be easily done with JustMock, but what if the method being tested has been invoked directly before your test method.

Note that, if ShouldCompileStaticCallOnJIT() is executed before ShouldPassIfStaticCallIsCalled(), the second test will fail. To avoid this behavior you can use Mock.Initialize like this:

This will initialize the whole Foo class, with all its methods and properties.

Initializing your classes can prevent unexpected behavior in your test methods, however using it improper, could lower the performance of your tests, by increasing the time needed for them to execute. Therefore, it is recommended to check the next section of this article.

Partial Initializing Of Classes

Here we will use the previous Foo class and the same test methods, to check its logic. This time we won`t initialize the whole class, but only a known part of it.

Inside the test initialization we will invoke only the method, that we are testing against. We can do this the following way:

Using partial initialization can be very appropriate in scenarios, where your tests are written against certain class methods. Doing partial initialization instead of initializing whole classes can save you test execution time.

See Also