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
TypeMock Isolator 7.4.3.0
Visual Studio Professional 2012
Test code targets .Net Framework 4
NUnit 2.6

Please, please explain why the following test (contrived, but cut down from a real life scenario) fails when run under a release build. It works just fine under a debug build.

I expect it to pass under both build configurations.

    [TestFixture]
    [Isolated]
    public class Tester
    {
        [Test]
        public void TestPassesInDebugBuildButFailsInReleaseBuild()
        {
            var trap = Isolate.Fake.Instance<Trap>();
            Isolate.WhenCalled(() => trap.Set()).WillReturn(true);

            var caughtOut = new CaughtOut();
            caughtOut.FallOver();
        }
    }

    class Trap
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(Trap));

        public bool Set()
        {
            try
            {
                return true;
            }
            catch (Exception ex)
            {
                Log.Error("");
                return false;
            }
        }
    }

    public class CaughtOut
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(CaughtOut));

        public void FallOver()
        {
            Log.InfoFormat("{0}: Application={1}",
                MethodBase.GetCurrentMethod().Name, "foo");
        }
    }


Failure message and call stack:
TypeMock.TypeMockException :
*** Unexpected Call to log4net.ILog.InfoFormat()
at dp.a(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at Typemock.Interceptors.Profiler.ReflectionCallbacks.OnGetReturnReflectionCallback(Object context, String typeName, String methodName, Object methodParameters, Boolean isDecorated, Boolean isInterceptedType, Object[] arguments)
at Typemock.Interceptors.Profiler.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType, Object p1, Object p2, Object p3)
at Mock0000ILog.InfoFormat(String, Object, Object)
at TypeMockTest.CaughtOut.FallOver() in Tester.cs: line 48
at TypeMockTest.Tester.TestPassesInDebugBuildButFailsInReleaseBuild() in Tester.cs: line 20
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Boolean A_5, Object[] A_6)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
at Typemock.Interceptors.Profiler.ReflectionCallbacks.OnGetReturnReflectionCallback(Object context, String typeName, String methodName, Object methodParameters, Boolean isDecorated, Boolean isInterceptedType, Object[] arguments)
at Typemock.Interceptors.Profiler.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
at TypeMockTest.Tester.TestPassesInDebugBuildButFailsInReleaseBuild() in Tester.cs: line 0
asked by hebbja2 (6.2k points)

1 Answer

0 votes
Hi,

It doesn't reproduce on my machine. Please try the latest version available at https://www.typemock.com.
Are you trying to fake the logger? If so, you should fake the static methods of log manager with:
Isolate.Fake.StaticMethods<RealLogger>();

If you want the the static ctor to be called use:
Isolator.Invoke.StaticConstructor<T>()


Let me know if it helps.
answered by alex (18k points)
...