Your official information source from the .NET Web Development and Tools group at Microsoft.
Previously I gave an overview of new tooling features for ASP.NET MVC Framework that we are hoping to make available during MIX 2008 timeframe. You can read more about Overview of MVC Tooling Features for MIX 2008 here.
Goals: ASP.NET MVC Framework is Microsoft's implementation of MVC framework which is hugely popular in the industry for best practices and conventions. In lines with best practices one of the goals of this new ASP.NET framework is to enable easy unit testable web applications. To ease unit testing and to make it part of our regular application development workflow Visual Studio is introducing integration of unit test projects with ASP.NET MVC Application. Many in the community are already familiar with and are using test frameworks liked Visual Studio Unit Test, NUnit, MBUnit etc. If you have Visual Studio Unit Test framework on your machine (i.e. in Visual Studio 2008 SKUs Professional and Above) then on creation of ASP.NET MVC Web Application you will automatically be prompted to create a test project. Not only that, due to the popular community request Visual Studio will now also provide a mechanism to extend this test framework system to integrate external unit testing frameworks like NUnit, MBUnit, xUnit etc.
Today I will be walking you through this new Test Framework integration for MVC Projects. Our goal today is:
At the end we want to get to a point where your test framework of choice shows up in the drop down when you try to create a MVC Application (like 'NUnit' does in the figure below):
(Fig 1: Create Test Project Dialog Box)
Applies To: This article applies to Visual Studio 2008 with ASP.NET MVC Framework Mix 2008 CTP installed. This documentation is pre-release documentation intended to provide insights to the community on the work being done by MS on ASP.NET MVC Framework, we are still in development phase so please do note that this is subject to change, but we believe this is very close to what you can see during MIX timeframe.
Video: I have also created a screen cast (approx 30 mins in length) which covers the concepts of this post in detail, we will be making it available here soon...
Step 1: Creating Test Project Templates : There is a very succinct article on MSDN on how to create Project Templates. You can find this article at http://msdn2.microsoft.com/en-us/library/s365byhx.aspx. Although the process may vary depending on the type of unit test framework and mock objects you choose, I am summarizing the process in context of MVC Test Project Template which I created using NUnit framework and Rhino Mocks library.
Step 2: Understanding Test Project Registration: We are introducing a very easy registry based registration model for your test project templates. Please refer the registry structure below:
(Fig 2: Test Framework Registry Info)
We have a new MVC key under Visual Studio 9.0 registry location as highlighted above. As you can see above I have NUnit and VisualStudio as my available test frameworks. This is what is showing up in the screen shot of "Create Test Project" dialog box in Fig 1 above. If you would like to add more test frameworks please go ahead and create one more key under 'TestProjectTemplates' key.
On the right side you see various string values, let me go ahead and explain what each one of these mean:
Also one point to note over here is that VS Test Framework selection system will create a test project for the same language as your primary MVC Application Project. The same registry strings that we just discussed above can be replicated at the top node (e.g. 'VisualStudio') that I have highlighted in the Fig 2 above. I would recommend having that replicated as it allows Visual Studio to fall back on this template in case your primary MVC Application is of languages like 'IronPython' etc. In nutshell that is the default template for that particular test framework within VS.
Summary: On completing the steps above, when you go to File--> New Project --> Language --> Web and try to create a new "ASP.NET MVC Web Application" project then the dialog box presented in Fig1: will show up with your newly registered Test Framework in the drop down.
Hope this will get you unit testing your projects more and more...!!
Vishal R. Joshi | Program Manager | Visual Studio Web Developer
PingBack from http://www.biosensorab.org/2008/02/18/aspnet-mvc-test-framework-integration/
New versions of the Microsoft forums are out A link on how to optimise production ASP.NET web sites How
Vishal’s earlier blog post, ASP.NET MVC Test Framework Integration , outlined the motivation and steps
摘要本期共有7篇文章(实际上有12篇文章,这两天不知为何网络状况一直不好,很多国外网站都上不去,只好暂时作罢):深入ASP.NETAJAX:对象继承体系使用ASP.NET3.5和自定义层...
摘要本期共有7篇文章(实际上有12篇文章,这两天不知为何网络状况一直不好,很多国外网站都上不去,只好暂时作罢):深入ASP.NETAJAX:对象继承体系使用ASP.NET3.5和自定义层级数...
TDD:IntroductiontoRhinoMocks
http://weblogs.asp.net/stephenwalther/archive/2008/03/22/tdd-int...
The ASP.NET MVC 1.0 Release Candidate (RC) is finally out, and we wanted to give returning MVC users