This article is a follow up to my previous post and it will show you how to get started with writing MSpec specifications (tests) for ASP.NET MVC2.
- Create the ASP.NET MVC 2 application. I’ve named the application MSpecMvcApplication and I made sure that it’s using the same .NET Framework version as my “Machine.Specifications.dll” was built against.
- Upon clicking OK, you’ll be asked if you want to create a unit test project, to which you should answer “Yes”. Note that there will be some irrelevant dlls referenced but this is for a quick demo on how to get up and running with writing MSpec tests.
- You should end up with two projects
- Add the “Machine.Specifications.dll” to the references.
- Open up “HomeControllerTest.cs” and replace the code with:
- Build the solution and run the test as follows:
- If all goes well you should see:
- This is not a “real” test, because there is no context or test condition. So a proper test would be something like:
In my next post I’ll try and explain what this code is doing but if you can run it, you’ll see
which is the result of a “real” test.