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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:05:13+00:00 2026-05-12T17:05:13+00:00

I am struggling a bit to understand how the new AAA syntax works in

  • 0

I am struggling a bit to understand how the new AAA syntax works in Rhino Mocks. Most of my tests look like this:

    [Test]
    public void Test()
    {
        //Setup
        ISth sth= mocks.DynamicMock<ISth>();

        //Expectations
        Expect.Call(sth.A()).Return("sth");

        mocks.ReplayAll();
        //Execution
        FunctionBeingTested(sth);
        //...asserts, etc

        //Verification
        mocks.VerifyAll();
    }

How would it look like using AAA syntax?

  • 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-12T17:05:13+00:00Added an answer on May 12, 2026 at 5:05 pm

    Most probably like this:

    [Test]
    public void Test()
    {
        // Arrange
        ISth sth= MockRepository.GenerateMock<ISth>();
    
        sth
          .Stub(x => x.A())
          .Return("sth");
    
        // Act
        FunctionBeingTested(sth);
    
        // Assert
    }
    

    To really benefit from the new AAA syntax, you have to change your mind a bit. I try to explain.

    There is a major difference in my proposal: there is no “Expect-Verify”. So I propose to not expect the call, because there is a return value. I assume that the method can’t pass the test when it didn’t call sth.A, because it will miss the correct return value. It will fail at least one of the other asserts.

    This is actually a good thing.

    • you can move the Stub to TestInitialize, it does not hurt when the stubbed method is not called in a test (it’s not an expectation). Your tests will become shorter.
    • Your test does not know “how” the system under test does the job, you only check the results. Your tests will become more maintainable.

    There is another scenario, where you actually need to check if a method had been called on the mock. Mainly if it returns void. For instance: an event should have been fired, the transaction committed and so on. Use AssertWasCalled for this:

    [Test]
    public void Test()
    {
        // Arrange
        ISth sth= MockRepository.GenerateMock<ISth>();
    
        // Act
        FunctionBeingTested(sth);
    
        // Assert
        sth
          .AssertWasCalled(x => x.A());
    }
    

    Note: there is not return value, so there is no Stub. This is an ideal case. Of course, you could have both, Stub and AssertWasCalled.


    There is also Expect and VerifyAllExpectations, which actually behaves like the old syntax. I would only use them when you need Stub and AssertWasCalled in the same test, and you have complext argument constraints which you don’t want to write twice. Normally, avoid Expect and VerifyAllExpectations

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

Sidebar

Related Questions

I new to Ruby and struggling to understand what is going on in this
I'm struggling a bit to understand why this code snippet does not compile. #include
I've been struggling a bit trying to get this to work. Getting clojure 1.3
I am struggling a bit to figure this one out. I'm working on an
I've been struggling a bit with this tiny problem - and I'm quite sure
New to wpf and therefore struggling a bit. I am putting together a quick
I am not a programmer, I am struggling a bit with this. I have
The problem is simple, but I'm struggling a bit already. Server server = new
I'm struggling a bit to understand how to use Scala's abstract types in as
I'm trying to understand how the things in Cocoa works but I'm struggling with

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.