Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit tests not discovered in Visual Studio 2019

The tests are present at Test Explorer but run command has no effect.

Looking at Output windows, for Test outputs it shows many errors like this:

 MSTestAdapter failed to discover tests in class 'UnitTests.Adhoc' of assembly 'some test.dll' because Method not found: 'System.String Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.get_DisplayName()'..
like image 739
MiguelSlv Avatar asked Mar 24 '20 15:03

MiguelSlv


People also ask

How do I run all unit tests in Visual Studio?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).

How do I enable test in Visual Studio?

To enable Live Unit Testing, select Test > Live Unit Testing > Start from the top-level Visual Studio menu.

How do I get unit test coverage in Visual Studio?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.


2 Answers

Found out that had some assembly conflict not signal by visual studio as usual on the references tree node.

Removing Microsoft.VisualStudio.TestPlatform.TestFramework reference and adding again did the trick.

Here de difference at the project file:

Before:

<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\..\packages\MSTest.TestFramework.2.0.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\..\packages\MSTest.TestFramework.2.0.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>

After:

<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
like image 186
MiguelSlv Avatar answered Sep 19 '22 20:09

MiguelSlv


For me, the other solutions didn't work as I e.g. did not have a reference to the package 'Microsoft.VisualStudio.TestPlatform.TestFramework'. It turned out that the solution for me was updating the Target Framework of the test projects from .NET Core 2.0 to .NET Core 3.1. Everything was working as before when changing that. I'm not sure what caused the issue, but I think it was a combination of three packages. For full reference, these are the ones (with version) I am now using with .NET Core 3.1:

Microsoft.NET.Test.SDK

MSTest.TestAdapter 2.1.1

MSTest.TestFramework 2.1.1

On Visual Studio 16.5.2

like image 30
Rob Houweling Avatar answered Sep 17 '22 20:09

Rob Houweling