Part 1: Creating the Sample Project (including unit test project)
First of all, we need to create our test solution, which will include our sample ASP.NET MVC 4.0 project and our Unit Test project. Let’s get rolling.
- Create a new MVC Project in Visual Studio.
- Make sure the target Framework is supported by your TeamCity CI Server version (in this case .NET Framework 4.0)
- Create a Unit Test project along with it when creating the project in Visual Studio
- Once the application is created, compile it and run it to make sure everything works correctly.
- Do a few basic modifications on the Home controller to have your own personal messages displaying on the page. In my case I’m just changing the ViewBag.Message properties for the Index, About and Contact actions on the HomeController.cs class.
Since we just created a unit test project, we are now able to run the tests for our MVC application. Let’s do it right away.
Click on TEST/Run/All Tests. This will run all the tests in your project. You will be able to see the tests running, and you will get a failure.
The reason is the default unit test is comparing the default ViewBag.Message that you just changed. Lets change the Unit Test message to match the new one. After changing the message for the correct one, and running the tests again, you should get a success message for the unit tests that ran.
This is a fairly trivial setup, which doesn’t really prove much, but the whole point is setting up TeamCity to build, test and deploy our project on our server environment, so let’s leave it like that for now.