So for the past few months I’ve been working on internal projects (hence no blogging – there’s nothing to share). For one of the projects, a complete rewrite of an internal site currently in ASP (woohoo, VBScript!) to MVC. Admittedly it’s only MVC 2.0  for various reasons and boy, do I regret that choice after seeing the new 3.0 tools at MIX.

Obviously MVC gives me (and my minions) the opportunity to test properly and part of that is code coverage. However I had real problems getting it to work, every time I turned code coverage on the MVC project MSTest would barf with Could not find WebDev.WebServer40.Exe. Why on earth would it want that? I don’t need the web application spun up, I’m just testing the controllers. I bugged a couple of mailing lists, and even went nuclear and emailed Phil Haack. He suggested starting a new test project, so I did, enabled code coverage, checked all the project boxes and still got the problem. Bum.

After having a couple of days messaging with AntiXSS (there will be a new beta of the encoding library soon with ASP.NET 4.0 swap out support) I went back to this. I loaded up the test projects in notepad and did a compare, nothing was particularly different. I removed a couple of odd references which referred to web tests, still nothing. So, in a fit of desperation I loaded up the local.testsettings file in notepad … and there was something strange,

 

<CodeCoverage keyFile="ssladmin.snk" xmlns="">
    <Regular>
        <CodeCoverageItem binaryFile="SSLAdmin.Model\bin\Debug\SSLAdmin.Model.dll" pdbFile="SSLAdmin.Model\bin\Debug\SSLAdmin.Model.pdb" instrumentInPlace="true" />
        <CodeCoverageItem binaryFile="SSLAdmin.Repositories\bin\Debug\SSLAdmin.Repositories.dll" pdbFile="SSLAdmin.Repositories\bin\Debug\SSLAdmin.Repositories.pdb" instrumentInPlace="true" />
    </Regular>
    <AspNet>
        <AspNetCodeCoverageItem id="62cc324d-bf2f-4a6d-9b97-85aaec4d6e77" name="SSLAdmin.Web" applicationRoot="/" url="http://localhost:0/" />
    </AspNet>
</CodeCoverage>

What on earth is that ASP.NET node? That looks rather suspicious. Turns out that’s the culprit. What I had done was simply check the projects in the code coverage detail dialog;

Cover Coverage Detail Dialog

You can see by the little icons next to the projects that the details screen knows it’s a web project, and there the problem lies, MSTest will automatically try to wire up a web project hosted like this to run under a web server. So how do you fix it? Simple, uncheck that tick box next to your project and instead click the Add Assembly button, browse down to your MVC assembly in your project and select it, it’ll then appear as a normal DLL, with the cog beside it. No more attempts will be made to start a web server and you finally have code coverage over your assembly which works under the TFS build servers. So now I have an easier time reviewing the code the rest of the team is checking in …

Technorati Tags: ,