If writing a Java unit test with mocking using JMock, should we use
Mockery context = new Mockery()
or
Mockery context = new JUnit4Mockery()
What is the difference between the two, and when should we use which?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
@Rhys It’s not the
JUnit4Mockerythat replaces the need to callassertIsSatisfied, its theJMock.class(combined with the@RunWith). You wont need to callassertIsSatisfiedwhen you create a regularMockery.The
JUnit4Mockerytranslates errors.By default, expectation exceptions are reported in Junit as
ExpectationError, so for example, usingyou’ll get
and using,
you’ll get
The JUnit4Mockery converted the ExpectationError to an java.lang.AssertionError which JUnit deals with. Net result is that it’ll show up in your JUnit report as an failure (using JUnit4Mockery) rather than an error.