Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 854013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:51:11+00:00 2026-05-15T07:51:11+00:00

If writing a Java unit test with mocking using JMock, should we use Mockery

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:51:12+00:00Added an answer on May 15, 2026 at 7:51 am

    @Rhys It’s not the JUnit4Mockery that replaces the need to call assertIsSatisfied, its the JMock.class (combined with the @RunWith). You wont need to call assertIsSatisfied when you create a regular Mockery.

    The JUnit4Mockery translates errors.

    By default, expectation exceptions are reported in Junit as ExpectationError, so for example, using

    Mockery context = new Mockery();
    

    you’ll get

    unexpected invocation: bar.bar()
    no expectations specified: did you...
     - forget to start an expectation with a cardinality clause?
     - call a mocked method to specify the parameter of an expectation?
    

    and using,

    Mockery context = new JUnit4Mockery();
    

    you’ll get

    java.lang.AssertionError: unexpected invocation: bar.bar()
    no expectations specified: did you...
     - forget to start an expectation with a cardinality clause?
     - call a mocked method to specify the parameter of an expectation?
    what happened before this: nothing!
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing my unit test cases for a Java project using Scala (JUnit
I am new to Java and am trying to run a unit test on
I have got to know that src/test/java is used for writing unit tests. I
I am using Spring test framework for writing unit tests using maven as the
I am writing a Java client/server GUI application using sockets and here is the
I want to unit test a Java application that fetches mails from an email
I'm writing a unit test for a method that contains the following line: String
I'm writing unit tests for Spring Framework 2.5 using JUnit. More specifically, I'm using
Any Java unit testing framework that supports writing unit testing code like this: Collection<AType>
I'm writing a unit test for a method that packs boolean values into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.