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

The Archive Base Latest Questions

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

I am trying to get a better code coverage with my unittests, and recently

  • 0

I am trying to get a better code coverage with my unittests, and recently I switched to using RhinoMock for my Mocking needs.

But I have got a question with how to write a specific unit-test, the Save() function.

I have an IView interface with several functions to retrieve values from the view (aspx page), examples are GetUsername(), GetPassword(), GetAddress() and GetCountry().

When the user clicks the submit button I want to have tests that tests if all these functions are actually being called. So I wrote this test:

    [TestMethod]
    public void MainController_Save_ShouldRetrieveLUsername()
    {
        //Initialize the IView and Controller
        InitViewAndController();

        //Trigger the Save function triggering the controller 
        //to collect information for storage
        _controller.Save();

        _view.AssertWasCalled(s => s.GetUsername(), o => o.Repeat.Once());
    }

Now finally comes the question, considering the aspx contains 15 input fields that needs to be saved, is there a better way to test this behaviour that writing and maintaining 15 of these tests?
On one hand test should be simple and optimally only one Assert, but 15 of these functions feels like a waste.

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

    Instead of testing whether these functions are called (they look more like properties instead of functions, BTW), you should check the results of the Save function. You should treat your test code more like a black box and try not to insert too much of its interior knowledge into your tests. This way your tests will be less brittle when the Save code changes.

    Google for “state based testing“.

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

Sidebar

Related Questions

I'm trying to get this piece of code working a little better. I suspect
I'm trying to get better at using MVC/MVP style patterns with my WinForm apps
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I'm trying to get the grails code coverage plugin to work based on these
I am trying to get better about minimizing any unnecessary markup and using optimal
I'm trying to get some better logic behind this before I start writing code.
I'm playing around with some code katas and trying to get a better understanding
I am trying to get better at c++. I have a Test class and
I'm working through previous years ACM Programming Competition problems trying to get better at
I'm trying to get a better understanding of how Windows, 32-bit, calculates the virtual

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.