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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:24:43+00:00 2026-05-31T04:24:43+00:00

In writing unit tests, for each object that the unit interacts with, I am

  • 0

In writing unit tests, for each object that the unit interacts with, I am taking these steps (stolen from my understanding of JBrains’ Integration Tests are a Scam):

  1. Write a test in the unit to ensure it is sending the correct call and params to the collaborating object
  2. Write a test in the unit that ensures it handles all possible responses from the collaborating object. These responses are all mocked so the unit is tested in isolation.
  3. Write a test in the collaborating object to make sure it accepts the call and params.
  4. Write tests to make sure each possible response is sent back.

My question comes around when I decide to refactor an object that has responses mocked in step 2. If I change the way the object responds to a call, none of the tests that other objects have for that call will fail because they have all been mocked to match the old style. How do you keep mocks up to date with the objects they are mocking? Is there a best practice for this? Or have I completely misunderstood things and am doing it all wrong?

  • 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-31T04:24:45+00:00Added an answer on May 31, 2026 at 4:24 am

    I do it this way.

    Suppose I have to change the responses from interface method foo(). I gather all the collaboration tests that stub foo() in a list. I gather all the contract tests for method foo(), or if I don’t have contract tests, I gather all the tests for all the current implementations of foo() in a list.

    Now I create a version control branch, because it’ll be messy for a while.

    I @Ignore (JUnit speak) or otherwise disable the collaboration tests that stub foo() and start re-implementing and re-running them one by one. I get them all passing. I can do this without touching any production implementation of foo().

    Now I re-implement the objects that implement foo() one by one with expected results that match the new return values from the stubs. Remember: stubs in collaboration tests correspond to expected results in contract tests.

    At this point, all the collaboration tests now assume the new responses from foo() and the contract tests/implementation tests now expect the new responses from foo(), so It Should All Just Work.(TM)

    Now integrate your branch and pour yourself some wine.

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

Sidebar

Related Questions

I'm writing many unit tests in VS 2010 with Microsoft Test. In each test
I am writing unit tests for objects that are cloned, serialized, and/or written to
How would go about writing proper unit testing (and integration testing for that matter)
I have a PersonDao that I'm writing unit tests against. There are about 18-20
I am writing a set of integration tests (Unit tests with MS Test which
I'm writing unit-tests for an app that uses a database, and I'd like to
I'm writing unit tests for a project (written in PHP, using PHPUnit) that have
Context I'm writing a Haskell module that represents SI prefixes: module Unit.SI.Prefix where Each
When writing unit tests, do you place your tests inside the assembly you wish
I am writing unit tests for some of my code and have run into

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.