.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Unit Test in MVC. What frameworks do you suggest?

Posted By:      Posted Date: September 12, 2010    Points: 0   Category :ASP.Net
Hello,What Unit Test Framework and Mock would you advice me for test MVC projects.Thank you,Miguel

View Complete Post

More Related Resource Links

Generation Test: Automated Unit Tests for Legacy Code with Pex


Creating and maintaining a unit test suite for legacy code can be a challenge. Pex automatically produces a small test suite with high code and assertion coverage.

Nikhil Sachdeva

MSDN Magazine December 2009

Unit Testing: Apply Test-Driven Development to your Database Projects


Jamie Laflen extols the benefits of TDD when applied to database development-and supplies some useful techniques along the way.

Jamie Laflen

MSDN Magazine Launch 2008

Unit Testing: Exploring The Continuum Of Test Doubles


Creating and using mock component servers simplifies unit testing. Use these examples to get started.

Mark Seemann

MSDN Magazine September 2007

Unit Testing: Mock Objects to the Rescue! Test Your .NET Code with NMock


The problem: unit testing libraries, especially data access components, that have a complex set of dependencies. The solution: providing a dynamic mock implementation of your data access classes. Here the author explains just how to make testing easier and more reliable using NMock.

Mark Seemann

MSDN Magazine October 2004

Who know some tools can help to create fake data which was used in unit test of asp.net mvc project

I was using aps.net mvc unit test, and want to create fake data instead of using real database connection, but the Linq query code and real database was huge and complicated, create fake data in unit test which can mimic real database was a huge job! Who knows some tools can help me to decrease size of real database and create mimic fake data for unit test. Thanks

How do I unit test HttpContext



I have a class library that uses HttpContext a lot, but I am having trouble writing unit tests for the functions. e.g. System.Web.HttpContext.Current.Request.ApplicationPath always return null, that makes class library throws exceptions everywhere.  I am not allowed to change the source codes of class library, so please let me know how to write test cases against it.


How to unit test C# Web Service with Visual Studio 2010 ultimate


I have webservice running, how to test those web methods using the Test features of Visual Studio 2010.

As with normal web reference i am not able to create the classes and call the webmethods inside the test class.

Write Unit Test for method with parameter


I'm trying to build my first MVC site and also write unit test for the first time.  I can't figure how to write unit test for methods that take parameters.  How do I write a test method for this controller action?

public class CustomerController : Controller

        public ActionResult Details(int id)
            var customerDetails = (from c in _entities.Customers
                                  where c.PK == id
                                  select c).FirstOrDefault();

            return View(customerDetails);


Unit Testing Error - The unit test adapter failed to connect to the data source or to read the data


I'm using VSTS 2K8 and I've set up a Unit Test Project. In it, I have a test class with a method that does a simple assertion. I'm using an Excel 2007 spreadsheet as my data source.

My test method looks like this:

"Dsn=Excel Files;dbq=|DataDirectory|\\MyTestData.xlsx;defaultdir=C:\\TestData;driverid=1046;maxbuffersize=2048;pagetimeout=5",
public void State_Value_Is_Set()

Visual Studio Unit Test for Visual Web Developer 2010 Express



I am using ASP.NET MVC and want to have Unit Test functionality integrated within Visual Web Developer 2010 Express (or Visual Studio LightSwitch). Is it possible and if so, what is the recommended/best way to get it?


Unit Test Url.Action




I have this method in a controller, but when i call from Unit test it is always null, If i run the website it works just fine.  How can i fake it so that Url.Action works
within my controller????? 

/// <summary>
        /// Set landing page URL
        /// </summary>
        /// <param name="contentSubType">Content sub type</param>
        /// <returns>Returns the landing page url</returns>
        public string GetLandingPageByContentSubType(ContentTypeLookup contentSubType)
            var landingPage = string.Empty;

            switch (contentSubType)
                case ContentTypeLookup.DesignArticle:
                    landingPage = SiteGlobalSettings.WebsiteUrl;
                    landingPage += Url.Action("DesignHome", "Design");
                case ContentTypeLookup.Product:
                    landingPage = SiteGlobalSettings.WebsiteUrl;
                    landingPage += Url.Action("ProductsHome", "Products");
                case Co

Why MVC best for UNIT test and not webforms if there is BL and Input Validation Layer?



ASP.NET MVC sessions and books say ASP.NET MVC enables to do unit testing as logic would be in controller independent to HTTP Request. So that controller can be unit tested indivisually. I do not think so people write their bussiness logic in controllers rather in seperate bussiness layer assembly. So there is no need to test controllers in bussiness perspective.

I do not think so we write web applications without a seperate Bussiness Layer. In this case Bussiness Layer also a clear seperation from UI. So BL can also be tested very well using UNIT testing frameworks either in MVC or in webforms.

then why should we chose ASP.NET MVC over WebForms in terms of UNIT Testing. Could anyone please clarify me in this regard if I'm wrong?

Deploying SQL CE dll's for VS2010 Unit Test


I'm trying to uint test the methods of a class which derives from a base class in another assembly. The base class uses Entity with SQL CE.

Normally the System.Data.SqlServerCe.dll and System.Data.SqlServerCe.Entity.dll are in the common build target directory, along with the base class assembly's dll. They don't get copied to the TestResults/<test>/Out directory. (The test assemblies do NOT target the comon build target directory; they use "bin/Release" or "bin/Debug".)

The base class assembly dll DOES get copied to the Out directory, along with other project dll's it depends on. These also have been copied to the bin/Debug (bin/Release) for the unit test project, but the SqlServerCe dll's are not there, either.

I tried using [DeploymentItem("System.Data.SqlServerCe.dll")] to copy them to the Out directory, but with no luck.

Adding the files to the Deployment list in the Test Settings, DOES copy them to Out. However, the unit test still fails in the same way... An exception is being thrown when the main entity class (derived from ObjectContext) is constructed with the connectionString.  The exception message is:

The specified store provider cannot be found in the configuration, or is not vali

WPF: If Heineken did MVVM Frameworks Part 4

MVVM is to have an instance of a particular Model (say currentPerson) inside my ViewModel (say PeopleViewModel) which is exposed to the View (say PeopleView). The View binds and edits the Model directly.

This definitely flies in the face of what most people consider to be the holy grail of MVVM pattern, but it's a fairly new pattern, so people are still finding their way with it every day, and this works for me very well. The reason I do what I do, is for the following reasons:

1.I have always had the luxury of being able to write my own UI specific Model classes. I would even do this if I was using some other Model classes first, such as LINQ to SQL or LINQ to Entity Framework. As these classes don't have everything a proper WPF Model class needs in my humble opinion. Though, they are pretty good, as they are Partial classes and use INotifyPropertyChanged/DataContract etc etc
2.I am a pragmatist and I do not like writing code for the sake of writing code. I have seen some MVVM apps where the author has had a Model with 50 properties on it, that are simply repeated in the ViewModel abstraction, where the ViewModel added nothing. On that day I decided I would never do that unless I have to.
3.I honestly see no harm in writing directly to the Model from the View, JUST SO LONG AS if the Model is InValid its data NEVER makes its way to the database. I honestly see no pro

Unit Testing SharePoint - Past, Present, and Sporm

As I described in SharePoint: The Wild West of Software Development there is a serious problem when you develop for SharePoint: ensuring quality through unit testing is really, really hard. And that's where a new open source tool just released today called sporm (SharePoint Object Relational Mapper) comes in. While sporm provides many benefits besides simplified unit testing I wanted to focus on this topic first, because sporm's approach, which models the entity framework in the way it supports POCO's, is a unique feature not available with other SharePoint tools like LINQ to SharePoint.

Test your skill in SQL Server

You will be given a series of 10 SQL Server related questions that are randomly selected. Since the questions are randomly selected, you will receive a different set of questions each time you start a test. At the end of the last question, you will be given your score. You can then start a new test session if you like.

Test Run: Fault Injection Testing with TestApi


Fault injection testing is the process of deliberately inserting an error into an application to determine whether it deals with the error properly. We'll explain how you can introduce faults into .NET applications at run time using the Managed Code Fault Injection APIs of the TestApi library

James McCaffrey

MSDN Magazine August 2010

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend