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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:43:55+00:00 2026-05-19T00:43:55+00:00

I would like to know how you guys handle something like this. Whats the

  • 0

I would like to know how you guys handle something like this. Whats the best practice..

Lest say I have a Method called Load on a presenter object

at first the method looks like this :

public void Load(ViewMode mode, int? id)
{
     if(mode == ViewMode.Modify)
          view.CurrentEntity = model.GetMyEntityById(id.GetValueOrDefault(0));
     else
          view.CurrentEntity = model.CreateNewEntity();
}

To test this code I have 2 tests using RhinoMock to setup expectations

[TestMethod]
public void Load_ShouldCallModelToGetEntityIfViewModeEqualsModify()
{
     IView view = _mockery.StrictMock<IView>();
     IModel model = _mockery.StrictMock<IModel>();

     Entity e = new Entity()

     using(_mockery.Ordered())
     {
          Expec.Call(model.GetMyEntityById(3)).Return(e)
          view.CurrentEntity = e;
     }
     _mockery.ReplayAll()

    Presenter sut = new Presenter(view, model);

    sut.Load(ViewMode.Modify, 3);

    _mockery.VerifyAll();
}

And I then I have another test that test the other path for the ViewMode.Add…

So my question is if I changed the Load method on the presenter to looks like

public void Load(ViewMode mode, int? id)
{

     view.CollectionA = model.GetListOfA();  <------ADDED THIS 
     view.CollectionB = model.GetListOfB();  <------AND THIS

     if(mode == ViewMode.Modify)
          view.CurrentEntity = model.GetMyEntityById(id.GetValueOrDefault(0));
     else
          view.CurrentEntity = model.CreateNewEntity();
}

now I have to add the expectation for both GetList methods in all my previous test or it will result in Expected 0 Actual 1. Also I will have to change my test name because in the test I expect far more than just calling the model to get an entity by its id.

So is there a best pratice for that. Is changing all my tests is the correct way to do things when I add call to some mocks, or there is a way to expect just some calls for previous test and add another test that would be something like :
[TestMethod]
public void Load_ShouldCallModelToObtainAListOfA();

and it would not make my other tests to fail.

I know its a vague question but if somebody understand what I ask please tell me how you handle this kind of situation with behavior tests.

Thank you very much
Breach

  • 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-19T00:43:56+00:00Added an answer on May 19, 2026 at 12:43 am

    It looks like you’re writing your unit tests to make sure certain methods are called to achieve the results you want. Don’t do this. It makes your tests very brittle and makes refactoring difficult.

    Instead, just test the behavior of your Load method, not how that behavior is implemented. From looking at your Load method, it’s populating a couple of collections and setting the CurrentEntity property. So your test should simply make sure that after the Load method was called, the collections are set and that the CurrentEntity is set to the one you expect.

    Stub out the model to return some canned responses for the various methods called on the model object and then run your test. Verify that the canned values come back in your view.

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

Sidebar

Related Questions

guys, i would like to know if sorl-thumbnail have any option to crop from
Okay guys, I would like to know the following comments I made in this
I would like to know what guys are using to make diagram of your
I guys. I would like to know how to build on of those Domain
Would like to know from all you guys what do you think about my
I would like to have your opinions regarding best practices to adopt in SQL
Hello brilliant guys on Stackoverflow, please I would like to know if in ASP.Net
I would like to know how can I create something that looks like what
Question 1) I would like to know whether ruby on rails have gems with
I would like to know what is the best platform out there to create

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.