Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeMock Isolator: WillThrow() bleeds across unit test boundaries?

I have two unit tests that use TypeMock Isolator to isolate and fake a method from asp.net's SqlMembershipProvider.

In test 1 I have:

        Isolate.WhenCalled(
            () =>
                Membership.CreateUser(...)))
            .WithExactArguments()
            .WillThrow(new Exception());

In test 2 I have:

        Isolate.WhenCalled(
            () =>
                Membership.CreateUser(...)))
            .WithExactArguments()
            .WillReturn(new MembershipUser(...));

When I run each test by itself they both pass successfully.

When I run both tests, test number 1 runs first and passes, then test number 2 runs and fails with the exception thrown in test 1.

Why would the WillThrow() instruction in test 1 "bleed over" to test 2? After all, test 2 explicitly defines different behavior - WillReturn()?

like image 251
urig Avatar asked Jun 23 '15 20:06

urig


1 Answers

If TypeMock behaviours are bleeding between tests, then the first thing to check is that you're cleaning up between tests. You can do this explicitly by calling Isolater.CleanUp(), or using the preferred approach which is to decorate either the test methods or the test class itself with the [Isolated] attribute.

like image 57
forsvarir Avatar answered Oct 05 '22 04:10

forsvarir