2012-02-25

Let's Code Jumi #126: Better Mocks (Part 1)

In the last episode there was a test failure with a misleading error message. I will evaluate JMock and EasyMock to see whether they would produce better error messages than Mockito.

Download as MP4

Episode Archive

2 comments:

  1. I just played around a bit with mockachino, which seems to report some (but probably not all) of the information you are looking for.

    @Test
    public void testMockachinoInOrder()
    {
    List mock = Mockachino.mock(List.class);
    mock.add("Foo");
    mock.add("Bar");

    OrderingContext order = Mockachino.newOrdering();
    order.verifyAtLeast(1).on(mock).add("Foo");
    order.verifyAtLeast(1).on(mock).add("Bar0");
    order.verifyAtLeast(1).on(mock).add("Bar");
    }

    se.mockachino.exceptions.VerificationError: Expected at least 1 call but got no calls
    Method pattern:
    add("Bar0")

    After:
    Mock:List:1.add("Foo")
    at VerifyTest.testMockachinoInOrder(VerifyTest.java:16)

    http://code.google.com/p/mockachino/

    ReplyDelete
  2. Towards the end of episode 127 you will see what is the information I'm looking for. Based on your example of Mockachino, its error messages do not list *all* actual and expected calls. I want to see all events before and after the first failure to get a complete picture of what happened and in what way it went wrong.

    ReplyDelete