Just like this guy, I didn’t create a unit test project for my MVC 4 project when it was first created. Now I want to go back and add one.
To that end, I created a new Unit Test Project.
Now, I right-click on a private method in one of my controllers, select Create Unit Tests, and get a popup dialog asserting:
Unit Test Generation Error: The following error was encountered while reading module
‘My.Project’: Could not resolve the type reference: [System.Web.Mvc, Version 3.0.0.0,
Culture=neutral, PublicKeyToken={why doesn’t MS support cut and
paste??}]System.Web.Mvc.AllowAnonymousAttribute.
AllowAnonymousAttribute is new to MVC 4. Why is the Unit Test Generator trying to resolve against the MVC 3 assembly though?
My.Project compiles and runs just fine, AllowAnonymousAttribute and all, and clearly is reverencing System.Web.Mvc, Version 4.0.0.0.
UPDATE
MyMvc.csproj contains
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\AspNetMvc.4.0.20126.16343\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference>
The DLL at HintPath is confirmed to be version 4.0.0.0
MyMvc.Test.csproj contains
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
This is no longer an issue in VS2012.
VS2012 no longer supports the add unit test wizard. Manually added unit tests work fine.