#24 make verify() fail when an earlier error had been thrown

EasyMock_2.4
open
EasyMock (33)
5
2012-10-05
2009-05-22
kind heart
No

(I couldn't fit "please" into the summary)

If the code under test happens to catch-and-swallow an AssertionError thrown by EasyMock, such as from an unexpected method call on a mock, the test might pass despite that error. If each control tracked the exceptions (such as AssertionError) thrown by mocks that it created, later its verify() method could report these and fail the test.

In the attached source example, the test subject happens to print the stack trace. But this could easily not be the case, and the offending (catch-and-swallow) code might be another (third-party) collaborator, not available to improve. Despite printing the error, this example clearly shows that it's possible to fail replay without failing the test, because the control needs an AssertionError to propagate all the way out of the code under test to the unit test framework during replay. The control could quite easily take advantage of the second opportunity to complain during verify().

Discussion

  • kind heart
    kind heart
    2009-05-22

    demonstration of problem

     
  • Henri Tremblay
    Henri Tremblay
    2009-05-23

    I see your point here. A code that swallow an AssertionError would seem like very bad code... But yes, it can happen.

    My only problem about this is that I think it will clash with issue 1896509.

    A least, it can't be in verify. I would need a new method for this.

     

  • Anonymous
    2011-10-20

    Excuse me, Henri, I couldn't find the issue 1896509 you mention on your comment.
    I'm interested in working with this, but I don't want my solution to clash with the issue.

    I would appreciate if you could tell me about it or link me to it.

    Thanks!

     
    Last edit: Anonymous 2013-11-20