Reputation: 22230
Perhaps this is easier if you let Visual Studio create the Unit Test project when it creates the MVC project. But seeing as how that wasn't done, how should I add a Unit Test project now?
Here's what I did:
After all of that, I see a little yellow hazard icon on the newly added reference, and I can't access any of its namespaces in the code.
Upvotes: 10
Views: 7649
Reputation: 4515
Using the Solution Explorer, browse your test Solution for References:
Right Click on "References"
Select Add Reference
Choose Solution from the menu on the left side and confirm that your primary project is checked. Like so:
That did it for me in VS 2013!
Upvotes: 1
Reputation: 11
This problem also exists when there path is not defined correctly so you should browse these Reference very carefully.
GoTo=>Reference=>Add Reference=>Click Browse(btn)=>Select Reference
then Ok
Upvotes: 1
Reputation: 22230
I figured it out. I forgot that there will be a warning message that goes along with the little yellow warning icon on a reference. So I went to the Error List and enabled "Warnings" in the filter. There was a message about mismatched .NET versions. The unit test project was using .NET 4.5 and the MVC project was 4.5.1. I changed the unit test project to 4.5.1, and voila, it works.
Upvotes: 30
Reputation: 39258
My theory is that you have to install MVC in the test project in order to satisfy the requirements. You can try to add the following nuget package from the package manager console to the unit tests project to intall MVC
Install-Package Microsoft.AspNet.Mvc
Alternatively you can use the Nuget UI manager in Visual Studio
Upvotes: 6