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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:56:45+00:00 2026-05-17T20:56:45+00:00

Today I finally started to write some unit tests for my new ASP.net MVC

  • 0

Today I finally started to write some unit tests for my new ASP.net MVC project seriously. Some unit tests, however, kept returning for every action in a each controller:

  • Perform a test whether the returned ActionResult is not null.
  • Perform a test whether the action returns a valid ActionResult if the ModelState is invalid.
  • Perform a test if the type of ActionResult matches a certain type (e.g. ViewResult or RedirectResult).

These three tests contained more or less the same code for every action. Since I like to avoid duplicate code, I thought of automating these ‘default’ kind of tests for every action. I did some quick Googles about it, but couldn’t find anything.

So:

  • Is automating default test a wise thing to do?
  • If yes, any scripts available or persons who already did something like this before?
  • If no one did something before, any suggestions on how to approach this?

Thanks for any replies!

  • 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-17T20:56:46+00:00Added an answer on May 17, 2026 at 8:56 pm

    I don think that having similar tests for different controllers is ‘duplicate’ code. The testing logic should be refactored so that it can be re-used. Re-used test code to test different controllers thus is not duplication.

    Have you looked at the TestHelpers within MvcContrib. I would think that alot of the common controller type tests have already been implemented. There are also other aspects that make testing a bit easier. That been said, it can used to set up your tests more easily. Have a look at this answer regarding Unit Testing Overkill.

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

Sidebar

Related Questions

We have a website running .NET 2.0 and have started using the ASP.Net HttpRuntime.Cache
Finally moved to Rails 3 for a new project and already running into a
Today I was listening to the Hanselminutes show about .NET 3.5 SP1...What's inside ,
Today at work we came across the following code (some of you might recognize
A month ago I finished reading the book Art of Unit Testing and today
I finally was able to complete the installation of TFS and started the creation
So, after 6 months of hard work finally released my application. Today I found
here is the problem, today I had a bad time debugging my project, the
Today, I ran into this weird problem with a user using Mac OS X.
Today I was working on a tab navigation for a webpage. I tried the

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.