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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:06:49+00:00 2026-05-13T01:06:49+00:00

I have just crafted the following test using Rhino mocks. Does my test look

  • 0

I have just crafted the following test using Rhino mocks. Does my test look valid and make sense to those more experienced with mocking?

I am a a little confused that I haven’t had to use the DynamicMock() or StrictMock() methods to create a seemingly valid test.

This test tests that the Add method was invoked on the supplied ICachingStrategy with the supplied parameters.

    object o = new object();
    DateTime d = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0);
    CacheStorageStyle s = CacheStorageStyle.Unmodified;
    string f = "test";

    //arrange  
    var stubStrategy = MockRepository.GenerateStub<ICachingStrategy>();
    var stubEncoder = MockRepository.GenerateStub<ICacheItemEncoder>();
    stubStrategy.Stub(x => x.Add(o,d,s,f)).Return("test:key");            
    stubEncoder.Stub(x => x.Encode(o,s)).Return(o);

    _mocks.ReplayAll();

    //act
    ICache c = new Cache(stubStrategy, stubEncoder);
    c.Add(o, d, s, f);

    //assert
    stubStrategy.AssertWasCalled(x => x.Add(o,d,s,f)); 
  • 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-13T01:06:50+00:00Added an answer on May 13, 2026 at 1:06 am

    The question is: does it succeed? Do you expect it to? If the answers are yes and yes, then the test is good. You can further test the test by forcing it to fail by commening out the call to Add() in your implementation. If the Add() method is not called, the test should fail.

    Here is the relevant documentation that explains the difference between stubs and mocks. The essential difference is that stubs “will never cause a test to fail.” They are there just to make the testing code work. The documentation further recommends that stubs should be preferred over mocks wherever possible.

    Your test appears valid to me because you are primarily interested in whether the Add() method was called, and you are explicitly asserting for that call. You’re not testing the other method calls, so you’re stubbing them instead of mocking them.

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

Sidebar

Related Questions

I have just started using RSpec and I copied the very simple test on
we have just started using a git account of our Django website project so
I have just built my first app in Xcode 4.3.2. I want to test
We have just started using EF 4.1 code first. I have a sql query
Have just finished my first web based application using Ruby on Rails. It was
I have just started using JSF 2.0 and faced a warmly welcomed issue. I
I have just started using django-cms so please forgive my newbieness. Every time i
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have just started playing with ASP.NET MVC and have stumbled over the following situation.

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.