Hi Lior,
I tried to assign a valid instance to the log field, as you suggested, using
ILog logField = MyClass_Accessor.log;
ILog logMock = LogManager.GetLogger(typeof(MyClass));
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.AssignField<ILog>(ref logField, logMock);
// ... code omitted ...
}
but i am still having the same problem (BTW, I could not find the
AssignStaticField method in the API). To be more precise, the first test that runs in a batch (independently from which one) passes, while the others fail. The error is always the same, a
TypeMock.VerifyException when my tested method calls a method on the
log field.
As you can see, since
log is a private static field, I am using the
accessor class generated by Visual Studio using MSTest in order to assign a value to it.
I also tried to disable automatic field mocking altogether in all tests with:
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.DefaultBehavior.AutomaticFieldMocking = false;
// ... code omitted ...
}
but that did not help either.
However in the documentation I found the following statement under
Natural Mocks™ - All About Constructors:
Static constructors will always be called. To mock a static constructor, call recorder.MockStaticConstructors(); this will mock all static constructors that were called while recording
According to this my static
log field should always be initialized, but
it is actually getting a proper value only during the first test, while it is being mocked in the others. Infact when I run the tests singularly, they always pass.
I really appreciate any help on this issue, since it is stopping us from moving to TypeMock 4.2.2 on our build server.
Thanks in advance
/Enrico