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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:22:46+00:00 2026-05-27T15:22:46+00:00

I’m using Moq to test behaviour of some void methods. Using MockBehaviour.Strict every call

  • 0

I’m using Moq to test behaviour of some void methods. Using MockBehaviour.Strict every call to the mock must be specified during Arrange step. This is resulting in a lot of tests not having any Assert (or Verify) step. The pass condition is simply that the test ran without throwing an exception. Am I missing something? Is the Arrange, Act, Assert pattern unsuitable when using strict mocks? Is there a more semantic way to layout these tests?

A trivial made up example…

[TestClass]
public void DeleteUser_ShouldCallDeleteOnRepository()
{
    // Arrange
    var userRepository = new Mock<IUserRepository>(MockBehavior.Strict);

    int userId = 9;
    userRepository.Setup(x => x.Delete(userId));

    var controller = new UserController(userRepository.Object);

    // Act
    controller.DeleteUser(userId);

    // Assert
    // ...?
}
  • 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-27T15:22:47+00:00Added an answer on May 27, 2026 at 3:22 pm

    Your mock is taking the place of a collaborator. It’s ideally doing one of two things:

    • Providing information or data
    • Doing a job

    When the mock is providing information or data, it’s enough that this should be a stub. You can set up the return value of the mock to the information required. This should be part of Arrange.

    When the mock is doing a job, the delegation can be verified. This is why you have Assert.

    What you’re doing with the strict interaction is ensuring that every single interaction is expected, basically saying, “Here’s what I expect to happen, and if anything else happens it’s wrong.” This is a different kind of testing to Act, Arrange, Assert, which says, “In this context, when I do this stuff, then I should get this outcome.”

    With a “nice” mock, you only need to worry about the interactions you’re interested in. So, for instance, if I’m a controller and I’m looking up some information in one repository, validating it with a validator, then saving the result in another repository, I might have several tests:

    • one to check that I’m validating against the right information
    • one to check how I’m responding to incorrect validation
    • and one to check that I save the item.

    With the strict mock, you have to do all the expectations, even if all you’re interested in is the “save”. By using a nice mock, we can split up the different aspects of behavior and only focus on one of them in each test.

    As an additional bonus, nice mocks allow you to do:

    • Given a context
    • When this event happens
    • Then this outcome should occur

    Whereas strict mocks make you do:

    • Given a context
    • Expect some stuff to happen
    • When I perform an event
    • Then go back and read what the outcome should have actually been.

    The first of these is generally considered more readable.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.