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 6184267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:30:27+00:00 2026-05-24T01:30:27+00:00

The most common use case for mocking is objA uses objB; use objA without

  • 0

The most common use case for mocking is

objA uses objB;
use objA without having objB populated/initialized

so that

@Mock
private UserInterface userInterface;

public void method() {
   MockitoAnnotations.initMocks(this);
   Client client;
   client.setUserInterface(userInterface);
   when(userInterface.getSomething()).thenReturn(new OutputType("f"));
   client.doSomething();
}

But what if we actually need only OUTPUT of objA ?
Let say that we don’t want to call objA.doSomething(); that returns SomeOutput, to get SomeOutput, so we could

  1. mock it for doSomething() to return SomeOutput; — doesn’t make much sense

  2. populate a variable with new SomeOutput(bla, bla, bla); without mocking anything at all.

I’m asking because I see programmers mocking the second way, which practically doesn’t make sense cause they just instantiate new SomeOutput(bla, bla, bla); and returns it via mocked objA;

Does it have any secret purpose ? I’m relatively new to mocking.

  • 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-24T01:30:28+00:00Added an answer on May 24, 2026 at 1:30 am

    I don’t know if I got you but I’ll try to answer.
    The goal of mocking (as you probably already know) is to isolate the piece of code you are testing. One unit test(I assume we are talking about unit test when there are mocking around)
    should only test one thing. In your example you could do that :

     new SomeOutput(bla, bla, bla);
    

    even if the result is the same you will obtain mocking the object in this case you are not isolating the class you want to test because you are “calling” a dependent component code

    Anyway I can suggest you to have a look at this book

    http://artofunittesting.com/

    even if it is in .net the concept are still the same

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

Sidebar

Related Questions

Sometimes I need to use several disposable objects within a function. Most common case
On most common platforms (the most important being x86; I understand that some platforms
What are the most common problems that can be solved with both these data
What's the most common way to deal with a series of block elements that
What are the most common reasons that I would be getting this error from
In a project of mine one common use case keeps coming up. At some
The documentation for __assume says "The most common use of __assume is with the
Most of the applications I've seen that use TCP, do roughly the following to
What are the most common/frequent memory leaks programmers use to run into when developing
It's common knowledge in most programming languages that the flow for working with files

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.