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

  • Home
  • SEARCH
  • 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 7821447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:39:16+00:00 2026-06-02T07:39:16+00:00

I am trying to write code to test a method by mocking the class

  • 0

I am trying to write code to test a method by mocking the class in JMock, this method internally calls three different methods(one of them is a private method). I set up the expectations for all the three internal methods. Then I call method, which is under test. The test case fails saying that it expected the private method to be called and it was not called. What is happening is that the two internal methods(with default access specifier) are mocked successfully but the private method is not mocked and in fact the control reaches inside the actual private method causing the problem. When I change the access specifier of the private method to default access, then everything works fine, but I don’t want to do that. Can somebody please explain this behavior and let me know how to resolve this problem

  • 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-06-02T07:39:17+00:00Added an answer on June 2, 2026 at 7:39 am

    JMock cannot mock private methods, plain and simple. Mockito cannot mock private methods either. If you really want to mock private methods, you need to use the PowerMock framework.

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

Sidebar

Related Questions

I'm trying ot write an integration test for one of my methods, that handles
I'm a student, and I'm trying to write and run some test code for
I'm trying to write a program to test student code against a good implementation.
I'm trying to write a unit test for a piece of code that generates
I am trying to write a test method to check if the List is
I am trying to write some code to test a database model. Both the
I am trying to write a unit test for our log out method. Among
I'am trying to write something like this: trait Typed[T] trait Test { def testMap:
I am trying to write a unit test for a method which takes an
I have been trying to figure out the best practices to write test-friendly code,

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.