Can't create MSTest Project

Mike VaughanEdwards 141 Reputation points
2020-08-15T12:02:04.873+00:00

I have visual Studio 2019 16.7.1
I tried to create an MSTest project but had problems so I followed the walk through at https://video2.skills-academy.com/en-us/visualstudio/test/walkthrough-creating-and-running-unit-tests-for-managed-code?view=vs-2019
I had the same problems as before:
In the code window
` using Microsoft.VisualStudio.TestTools.UnitTesting; had VisualStudio underlined with the message "The type or namespace VisualStudio does not exist in the namespace Microsoft.
The decorations [TestClass] and [TestMethod] were also underlined as not being recognised.
In the Solution Explorer window:
All items in the Dependencies/Packages have the yellow triangle & exclamation mark icon

This looks to me like something needs installing but I can't find what.

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
336 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 28,941 Reputation points Microsoft Vendor
    2020-08-17T07:01:00.713+00:00

    Hi MikeVaughanEdwards,

    I tested on my side and I reproduced this issue, please check the following screenshot.
    17923-test1.png

    This issue should be related to the NuGet package sources, please go to Tools > Options > NuGet Package Manager > Package Sources and uncheck the other package sources except nuget.org(https://api.nuget.org/v3/index.json)
    17924-test2.png

    After that, please remember to unload and reload your project (right-click your project > Unload Project) and wait for the Visual Studio to check and restore the NuGet Package completely. If this issue persists, please try to restart Visual Studio and create a new MSTest Project.
    17925-test3.png

    Best Regards,
    Tianyu

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 28,941 Reputation points Microsoft Vendor
    2020-08-19T07:44:53.567+00:00

    Hi Mike,

    Do you have any update?

    Part of MSTest project template's framework comes from Nuget Packages, VS will automatically download the missing packages for you when you create a new MSTest project. (Normally it take seconds)

    As for why all your items in the Dependencies/Packages have the yellow triangle, you should check these points:

    1.Make sure your machine can connection to Internet, cause VS will try to download the nuget packages from Internet.

    2.Tools=>Options=>Nuget Package Manager, enable these two options:
    18599-screenshot1.png

    3.The packages of MSTest project template are hosted in nuget.org(https://api.nuget.org/v3/index.json). So you need to make sure you have enabled this package source(Nuget Package Manager=>Package Source):
    18715-screenshot2.png

    You could follow steps above to resolve this issue, let me know if it helps or not.

    Best Regards,
    Tianyu

    0 comments No comments

  2. Mike VaughanEdwards 141 Reputation points
    2020-08-19T12:09:04.763+00:00

    Hi Tianyu

    Thanks very much. That fixed it. For some reason nuget was not there in the Tools\Options\NuGet Package Manager\Package Sources. I added the details copying your screen shot. Once that was accepted I went back to the project and refreshed the NuGetPackages and everything came right.

    0 comments No comments