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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:44:54+00:00 2026-06-04T20:44:54+00:00

When I design MVC apps, I typcially try to keep almost all logic (as

  • 0

When I design MVC apps, I typcially try to keep almost all logic (as much as possible) out of my app. I try to abstact this into a service layer which interfaces with my repositories and domain entities.

So, my controller methods end up looking something like this:

public ActionResult Index(int id)
{
    return View(Mapper.Map<User, UserModel>(_userService.GetUser(id)));
}

So assuming that I have good coverage testing my services, and my action methods are simple like the above example, is it overkill to unit test these controller methods?

If you do build unit tests for methods that look like this, what value are you getting from your tests?

  • 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-06-04T20:44:55+00:00Added an answer on June 4, 2026 at 8:44 pm

    If you do build unit tests for methods that look like this, what value
    are you getting from your tests?

    You can have unit tests that assert:

    1. That the GetUser method of the _userService was invoked, passing the same int that was passed to the controller.
    2. That the result returned was a ViewResult, instead of a PartialViewResult or something else.
    3. That the result’s model is a UserModel instance, not a User instance (which is what gets returned from the service).

    Unit tests are as much a help in refactoring as asserting the correctness of the application. Helps you ensure that the results remain the same even after you change the code.

    For example, say you had a change come in that the action should return a PartialView or JsonResult when the request is async/ajax. It wouldn’t be much code to change in the controller, but your unit tests would probably fail as soon as you changed the code, because it’s likely that you didn’t mock the controller’s context to indicate whether or not the request is ajax. So this then tells you to expand on your unit tests to maintain the assertions of correctness.

    Definitely value added IMO for 3 very simple methods which shouldn’t take you longer than a couple of minutes each to write.

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

Sidebar

Related Questions

My application is following the MVC design pattern. The problem I keep running into
I know there are a lot of MVC design patterns out there. It seems
I'm trying to figure out the best way to implement MVC design in my
This query is about MVC design pattern in general and not ASP.net MVC framework
I am trying to copy the MVC design pattern. And this is what I
Possible Duplicate: When should I create new Controller class in Asp.net MVC (Design Question)?
I am constanstly having problems with model design in MVC. Mostly all of my
I was reading this article on using the MVC design pattern in game development,
I am creating a simple application using the MVC design pattern where my model
Over the last few weeks I have been studying the MVC design pattern for

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.