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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:47:49+00:00 2026-05-26T16:47:49+00:00

There are some other variations of this question here at SO, but please read

  • 0

There are some other variations of this question here at SO, but please read the entire question.

By just using fakes, we look at the constructor to see what kind of dependencies that a class have and then create fakes for them accordingly.

Then we write a test for a method by just looking at it’s contract (method signature). If we can’t figure out how to test the method by doing so, shouldn’t we rather try to refactor the method (most likely break it up in smaller pieces) than to look inside it to figure our how we should test it? In other words, it also gives us a quality control by doing so.

Isn’t mocks a bad thing since they require us to look inside the method that we are going to test? And therefore skip the whole “look at the signature as a critic”.

Update to answer the comment

Say a stub then (just a dummy class providing the requested objects).

A framework like Moq makes sure that Method A gets called with the arguments X and Y. And to be able to setup those checks, one needs to look inside the tested method.

Isn’t the important thing (the method contract) forgotten when setting up all those checks, as the focus is shifted from the method signature/contract to look inside the method and create the checks.

Isn’t it better to try to test the method by just looking at the contract? After all, when we use the method we’ll just look at the contract when using it. So it’s quite important the it’s contract is easy to follow and understand.

  • 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-26T16:47:49+00:00Added an answer on May 26, 2026 at 4:47 pm

    This is a bit of a grey area and I think that there is some overlap. On the whole I would say using mock objects is preferred by me.

    I guess some of it depends on how you go about testing code – test or code first?

    If you follow a test driven design plan with objects implementing interfaces then you effectively produce a mock object as you go.

    Each test treats the tested object / method as a black box.

    It focuses you onto writing simpler method code in that you know what answer you want.

    But above all else it allows you to have runtime code that uses mock objects for unwritten areas of the code.

    On the macro level it also allows for major areas of the code to be switched at runtime to use mock objects e.g. a mock data access layer rather than one with actual database access.

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

Sidebar

Related Questions

I'm sure some variation of this question has been asked before but all other,
Is there any way using foursquare api or some other location based api to
Edit if you plan on answering this question please at least read it. Don't
Is there any way to update nested documents by id or some other field?
Is there a way to use the HAVING clause in some other way without
Is there any way to encapsulate an Iframe with some other element to simulate
In some sample codes there are methods and classes declared WITHIN other methods and/or
(I asked a variation of this question on comp.std.c++ but didn't get an answer.)
Yes, this is probably yet another greatest-n-per-group question... But I've tried at least a
I feel there is a simple solution to this -- I've looked at other

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.