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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:52:58+00:00 2026-06-06T20:52:58+00:00

I find myself now with an EF Code First DbContext and entity classes, which

  • 0

I find myself now with an EF Code First DbContext and entity classes, which I would prefer to exclude from unit testing right now, as Code First is not a critical requirement, and I would not unit test DB First generated classes, but above that I have a repository library, which are all copy and paste copies of one template, and then some view modes and controllers.

I would now like to adopt a TDD approach for the way forward, and add unit tests for view models that are not pure (property only) DTO’s, and my action methods. Am I going in the right direction, with the right coverage in mind? Then, how do I unit test actions? Some pointers to resources and tutorials would be nice.

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

    Ideally, in a perfectly TDD environment you would have tests for absolutely everything in your code – but some may consider that dogmatic and you don’t see a need to test your code-first-generated-database, so don’t do it 🙂 . You’re the developer, do what you want.

    I understand your feelings on the above, but if you want to develop in a true TDD style, you need to write a test before you code anything, then code to get the ‘green light’ on the test.

    The basic workflow would be as follows (starting on anything you wanted to add to your app past your DBContext)

    1. Realize you need a new feature for your MVC application
    2. Write a test that fails (because there is no actual code at this point)
    3. Write the new feature you were wanting to add to your application
    4. Run your test, if the test passes, move on to 5, if it fails, edit the code and repeat 4
    5. Refactor as needed and re-run the test to ensure that everything passes

    You will have a lot of tests, but you will have a very sound application as long as you are diligent about maintaining those tests.

    Keep a few things in mind when using TDD with MVC (or likely any development architecture):

    • Run your tests frequently
    • Make sure your tests all pass after they’ve passed once in the past (sounds obvious, but some people are crazy)
    • Make sure you can run your tests easily and quickly, preferably one or two clicks and the tests are run. This will allow you to more easily run them frequently – this is what the tests are here for.
    • Stick to it, it is easy to get lazy and just say, “yeah, I know this part will work, no need to test it,” but when you are looking at that code weeks/months/years from now and you are not as closely connected to it, you may carelessly change something and run your project’s tests (since it was developed using a TDD process) and notice everything passes. But, since there wasn’t a test for the part you changed, you have no evidence that the code is all working as planned. It sounds simple, but think of it as a forgotten ‘broken window’ that can lead to other problems.

    As far as writing tests specifically for MVC actions, I highly recommend this tutorial from MSDN and this book: Pro ASP.NET MVC 3 Framework (which is an overall great resource for MVC3, including TDD for MVC3) by Freeman and Sanderson.

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

Sidebar

Related Questions

Having been spoiled by ruby for so long, I now find myself having to
I find myself creating Converters often and would like to be able to: right-click
I find myself making repetitive mistakes typing keywords and sentences in my code comments.
I find myself writing a lot of functions in PHP that return HTML code.
I find myself writing the same verbose DOM manipulation code again and again: Element
I'm used to lazy evaluation from Haskell, and find myself getting irritated with eager-by-default
I find myself typing import numpy as np almost every single time I fire
I find myself often having to reposition subviews of a view after hiding or
I find myself using Resharper's convert to auto property refactoring a lot to remove
I find myself doing this repeatedy. $jq(button).filter(function(){ return this.id.match(/^user_(\d+)_edit$/); }).click(function(){ var matches = this.id.match(/^user_(\d+)_edit$/);

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.