TypeMock Insulator 4.2 Beta Publicly Available
TypeMock (now called) Insulator 4.2 Beta is publicly available. Check out the release notes.
One of my favorite new features is the improved mock chaining.
Take this class to be tested:
public class TestedClass1 { public IDictionary<string, object> Dictionary { get { throw new NotImplementedException(); } }<span style="color: blue">public object </span>Method(<span style="color: blue">bool </span>cond) { <span style="color: blue">if </span>(cond) { <span style="color: blue">return </span>Dictionary[<span style="color: #a31515">"true"</span>]; } <span style="color: blue">else </span>{ <span style="color: blue">return </span>Dictionary[<span style="color: #a31515">"false"</span>]; } }
}
The following test:
[TestMethod] [VerifyMocks] public void TestMethod1() { object trueObject = new object(); object falseObject = new object(); TestedClass1 target = RecorderManager.CreateMockedObject<TestedClass1>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.DefaultBehavior.CheckArguments(); recorder.ExpectAndReturn(target.Dictionary["true"], trueObject); recorder.FailWhenCalled(target.Dictionary["false"]); } object value = target.Method(true); Assert.AreEqual(trueObject, value); }
Would simply fail with:
Test method TestProject1.UnitTest1.TestMethod1 threw exception: TypeMock.VerifyException: TypeMock Verification: Method TestProject1.TestedClass1.get_Dictionary() has 1 more expected calls .
Now, it just passes.
Visual Studio cues are nice too.