lundi 30 novembre 2015

Shimmed method not used by test in Release mode

Within Visual Studio 2015 I have a test project to which I've added a fakes assembly.

In the unit test itself I create a shim for a static generic method that returns an instance to the generic type, such as:

using (ShimsContext.Create())
{
    ShimStaticClass.TheMethod<MyType>(() => instanceOfMyType);

    // ... code that uses StaticClass.TheMethod here ...
}

When the solution is built in debug mode the test runs fine and passes. However, when the solution is built in release mode the shimmed version of TheMethod does not get called, which is causing the test to fail.

I know that the shimmed method is not called because I've changed it to throw an exception by doing:

using (ShimsContext.Create())
{
    ShimForStaticClass.TheMethod<MyType>(() => 
    {
        throw new InvalidOperationException("Shim was called");
    });

    // ... code that uses StaticClass.TheMethod here ...
}

and this exception is not thrown.

I've turned on diagnostic logging and noisy verbosity for the fake but the build logs do not indicate any issues.

Aucun commentaire:

Enregistrer un commentaire