Isolator AAA: Verification

After creating fakes and setting behaviors. we come to the end of our journey (until next release, when new APIs will appear) – verification.

The syntax makes the tests much more readable. You specify exactly what you expect to have happened.

Verify comes in 3 flavors:

  • WasCalledWithExactArguments – The method was called at least once, with the exact parameters specified.
  • WasCalledWithAnyArguments – The method was called at least once, regardless of parameters.
  • WasNotCalled – Well, you can guess this one.

In future releases, we’re going to add more features around this, like number of times the method was called, more specific checks, and if specific instances got created.

Verify also works great with chains. Have a look at this example:

[TestMethod]
[Isolated]
public void RecursiveStubsWithChainExpectation()
{
RealLogger fake = Isolate.Fake.Instance<RealLogger>(Members.ReturnRecursiveFakes);

Isolate.WhenCalled(() => fake.GetSon().DoSomething(1)).WillReturn(13);

Assert.AreEqual(13, fake.GetSon().DoSomething(10));
Isolate.Verify.WasCalledWithExactArguments(() => fake.GetSon().DoSomething(10));
}

Note that the Verify clause checks that the entire chain was called. If only part of it was called, the Verify will fail, and you’ll get a nice VerifyException.

I encourage you to start using these APIs and give us feedback – on readability, coding experience, and fabulous success stories (if they are indeed related to the API).

We are already in the process of implementation of other existing features in the new syntax (first and foremost – static calls), and once they’re out I’ll post on them too. In the meanwhile – go play with these toys.

  • woonboo

    Chaining is very hard to read (IMO) unless you have the demo of it unchained side by side or intrinsic knowledge of the system. This chain (as in the previous blog) I can’t make heads or tails of – the other non-chained examples I can. Perhaps because something that isn’t chained lends itself to comments which immediately take away any confusion? Perhaps because it goes better with my ‘one line, one instruction’ mind set.

    I like how Typemock allows you to do either so that it becomes a preference thing rather than a ‘must’ (as it is in other frameworks I’ve seen).

    When the next version comes out will people have to who just got version 5 have to ‘re-buy’ version 6? Or is the license model more of a subscription model like MSDN – if 3 version comes out in a single year – lucky you.

  • Doron

    @woonboo: chains are indeed confusing, and the example Gil brought is borrowed from our testing classes so it does not make a lot of sense in a ‘business logic’ sort of way. Just replace fake.GetSon().DoSomething(1) with a chained call that makes sense to you and it should work.

    Regarding the license model: if you purchased Isolator and have a valid maintenance (which is yearly renewable) you will be able to upgrade to our latest and greatest.

TOP