hits counter

Typemock Isolator 5.1 Released

This major version adds static method support and non-public method faking to the AAA API. Check out the release notes.

I don’t like the reflective approach to testing private methods.

With the new additions to the AAA API, testing this class:

public class MyClass
{
public string Public()
{
return this.Private();
}

<span style="color: blue">private string </span>Private()
{
    <span style="color: blue">throw new </span><span style="color: #2b91af">NotImplementedException</span>();
}

}

can be done like this:

[TestMethod]
[Isolated]
public void PrivateTest()
{
    MyClass fake = Isolate.Fake.Instance<MyClass>();

    Isolate.WhenCalled(() => fake.Public()).CallOriginal();

    Isolate.NonPublic.WhenCalled(fake, "Private").WillReturn("FAKE");

    string fakePublic = fake.Public();

    Assert.AreEqual("FAKE", fakePublic);

    Isolate.Verify.WasCalledWithExactArguments(() => fake.Public());

    Isolate.Verify.NonPublic.WasCalled(fake, "Private");
}

I would like it better if it was like this:

[TestMethod]
[Isolated]
public void PrivateTest()
{
    MyClass fake = Isolate.Fake.Instance<MyClass>();

    MyClass_Accessor fakeAccessor = MyClass_Accessor.AttachShadow(fake);

    Isolate.WhenCalled(() => fakeAccessor.Private()).WillReturn("FAKE");

    Isolate.WhenCalled(() => fake.Public()).CallOriginal();

    string fakePublic = fake.Public();

    Assert.AreEqual("FAKE", fakePublic);

    Isolate.Verify.WasCalledWithExactArguments(() => fake.Public());

    Isolate.Verify.WasCalledWithExactArguments(() => fakeAccessor.Private());
}

Looks almost the same but there aren’t any method names in the test code.

They were able to do it for Natural Mocks. I’m sure they will eventually do it for AAA.

No Comments