Code coverage with Team build and MVC or any web application


  • I just need to create a code coverage and display it with the team build but I face a problem when I follow the normal steps, so my question was why the code coverage doesn’t appear with the team build? but there is no answer after little investigation here the result.
  • Fist the visual studio premium or Ultimate edition must be installed on the building machine so code coverage can viewed and calculated.

The MVC or the website needs additional test configuration and may normal configuration cause an error because I face the following error

Test Run Error. Cannot initialize the ASP.NET project ‘WebUIController’.
Exception was thrown: The web site could not be configured correctly; getting ASP.NET process information failed. Requesting ‘http://localhost:3352/VSEnterpriseHelper.axd’ returned an error: The remote server returned an error: (500) Internal Server Error.

You can check here a bug that closed because it can’t reproduced on Microsoft for this error

Microsoft Connect, click to see the bug

  • So I read many articles but the most important one as the following,  it’s very good but it’s not cover all my cases

http://blogs.blackmarble.co.uk/blogs/rfennell/archive/2009/04/15/team-build-code-coverage-and-mvc.aspx

So let’s start

  • First you will see that you have 2 test configuration files by default (you can add more config file  if you want) when you create new test project in any solution so you can use one of them as a local configuration and the other with the team build if you want,  so every configuration has different values, remember the way that selecting the testing configuration is different, it depends on  the place you will build your solution on,  for example if you build your solution on your machine then you will select the desire test configuration from Visual  Studio menu Test–>Select Active test
  • But if you build your solution on building machine using Team build so you will select this configuration from the build definition parameters window, when you create or edit build definition
Test Configuration in the solution

Test Configuration in the solution

  • Open the test configuration you want let’s say its TraceAndTestImpact.testsettings, just double click on it and select code coverage and select the dll you want but remember don’t select the web, you will configure it manually, and here is the tricky sometimes it’s OK and sometimes it give me the previous error in the Microsoft connect, any way don’t select it, save the file and close it.
Select code coverage

Select code coverage

  • Open the file again but this time with open with as XML and start adding new line to point to the Web dll as the class library but remember you have to set the absolute path because it’s different on the source folder in the build machine,so you just need to go there and find where the path to the dll on the server machine and put there.
Test Configuration in XMl

Test Configuration in XMl

  • Build your application on the build machine,  now you should see the code coverage for the class libraries and the MVC or the Web Application.

How to prevent some files from committed to the source control?



I will show another small tip which prevent file from committed to the source control or TFS 2010, I will  prevent the generated minifiy file that create by Microsoft Ajax Minifier.

Open Check-in policy

Open Check-in policy

Open forbedding pattern policy

Forbidden policy

Forbidden policy

Enter reguler expression that prevent .minifie files from from committed

Regulaer Expression

Regulaer Expression

Done.

 

How to prevent some file from committed to the source control

How to exclude file from the Source Control?



I will show a small tip of how to exclude a file from TFS 2010 or exclude file from source control, please see the following image, if you want to include just do the Vice versa.

Exclude file

Exclude file

That’s it, very small :-)

Vice versa

How to change the souce control?



I will show another small tip which will change the source control, just click the project that doesn’t has binding info and then click on the file source control and then choose change source control as you can see in the following  image

Open source control menu

Open source control menu

Now bind or unbind the files you want

Bind files

Bind files

That’s it

2-Why and How to use IBuildDetailes and BuildDefinition?



Hi, In this episode I will talk about why and how to use IBuildDetailes and buildDefination object to get valuable information throught the build, this very important because IBuildDetailes give you all information you need to know about the running build.

You can go to my episode 1 and download the process that I will use click-here

Part 1 BuildNumber

  • First you will create a clean Teamplate and start following the image with order number, this will get the buildDetails object and assign it to my variable so you can use it throughout the build process
Create BuildDetail variable

Create BuildDetail variable

You can download my process template from the episode 1 as I mention before

  • Right click on WriteBuildMessage task and choose properties and change BuildMessageImportance.High and give the message BuildDetail.BuildNumber
Use buildNumber

Use buildNumber

Just queue a new build and open click on view log and you will see it log your build number

Output the buildNumber

Output the buildNumber

Part 2 BuildDefinition

How to get infromation from the buildDefinition

  • When you create a new build definition you set the drop location
Set Drop location

Set Drop location

  • Now you can message the drop location as the following
Message drop location

Message drop location

  • Build and click on view log
View the drop location

View the drop location

  • You can also use the full path as the following
Full path

Full path

  • Build and see view log
View log for full path

View log for full path

  • You can see what the build definition hold
Build definition info

Build definition info

That’s it

Auto Deploy your Website for QA with Team Build



I need to Deploy the website to the QA machine with team build so I search for how to do that and I found very good article of Ewald Hofman which describe how you auto deploy your website and it’s very good post, but there  is 2 issues I faced when I implement this example

First Issue:

The Package folder that auto generated doesn’t generated on the Team build, the reason was very easy, because I don’t have Visual Studio installed on the Server machine, so by Installing the visual studio everything is now working and the generated package folder now exist.

Second Issue:

How to deploy the project to another machine, so you have to write the post build as the following

if “$(ConfigurationName)” == “Test” “$(TargetDir)_PublishedWebsites\MyProject_Package\MyProject.deploy.cmd” /Y /M:YourServerName/u:YourUserName /p:YourPassword

For more information with how to make package and deploy it using MSDeploy click-here

Note:
You have to see Ewald Hofman post because my post depend on it, because I didn’t want to repeat any examples

Using Microsoft Ajax Minifier with team build



2 weeks ago I had a problem with Microsoft Ajax Minifier on Team Build 2010 because my file doesn’t’ minify, and I post 3 posts title ” Why Microsoft Ajax Minifier dosen’t minfi the file when used with team build 2010? ” in ASP.NET, MSDN forum and Stackoverflow but with no result, the post has many views on both ASP.NET and MSDN forum but with no answer except very kind person “Sid Forcier” that try to help me but also with no result.

Part of the log file as the following

===================================================================
Using “AjaxMin” task from assembly “C:\Program Files\MSBuild\Microsoft\MicrosoftAjax\ajaxmintask.dll”.
Task “AjaxMin”
Done executing task “AjaxMin”.
Done building target “AfterBuild” in project “MVCWithAjax.csproj”.
===================================================================
And after hard investigation I found the solution, the problem was that when I set the build definition I make the drop folder inside the D:\ drive  and the Team build copy the source code to the C:\build\…., so the AjaxMin can’t find any CSS or js in the whole D:\ drive, only dlls.

And because the AjaxMin use search criteria to find the files and if it didn’t find just doesn’t do anything so it doesn’t give me any error in the log file as you can see, so all I had to do just change the path to the CSS and JS to my source folder on the Team Build server as the following

Using AjaxMinifier

Using AjaxMinifier

Remember how to use the partial path, its very important to know how to include a file and what is the wild card that you can use to refer to the path you want, here you can find good link to the MSDN that describe this point, click-here