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

197 views Asked by At

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()?

1

There are 1 answers

0
forsvarir On BEST ANSWER

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.