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