Unit tests not discovered in Visual Studio 2019
Asked Answered
B

5

14

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()'..

Bertine answered 24/3, 2020 at 15:22 Comment(0)
B
4

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" />
Bertine answered 24/3, 2020 at 15:22 Comment(1)
For me it worked to do "Rebuild All" on the visual studio solution.Denbrook
M
3

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

Mg answered 7/4, 2020 at 7:46 Comment(2)
With the .NET Core 2.2 this combination of dependencies works too.Ossetia
Thanks, I moved a test file from one project to another and it suddenly stopped working. This prompted me to add a ref to MSTest.TestAdapter which was not present in the second project!Sarene
M
1

You can go to the test options (Test -> Options) and turn up the logging level to trace, and then you might find more information. for me, it was because the test classes were not public, even though te.exe (https://learn.microsoft.com/en-us/windows-hardware/drivers/taef/) found the tests fine even when the classes were non public

[MSTest][Discovery][C:\Users\mgrandi\Code\git\blah\src\Services\blah\Test\blah.Tests\bin\Debug\net472\blah.Tests.dll] UTA001: TestClass attribute defined on non-public class blah.Tests.blah.Common.BondObjectSanitizerTest

Mihe answered 8/7, 2022 at 1:11 Comment(0)
P
0

My problem was that I had tests in one specific class that weren't recognized.

Turns out I'd cut and pasted a TestInitialize method that contained a TestContext that I wasn't using. For instance:

[TestInitialize]
public void ClassInitialize(TestContext context)

When I removed the unused TestContext all my tests were recognized:

[TestInitialize]
public void ClassInitialize()
Philine answered 20/9, 2021 at 17:12 Comment(0)
C
0

I encountered the same problem with vtest task in an Azure Devops classic Pipeline.

My problem was :

  • I was specifiying an OutDir when building the solution
  • the Search folder for the VsTest did not include the OutDir, so I was catching the test projects DLLs inside obj directories which led to the error :

MSTestAdapter failed to discover tests in class 'MyTestClass' of assembly 'C:\Mypath\MyTestsAssembly.dll' because Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified..

Setting the same VsTest Search folder as the solution's OutDir solved the problem.

Callboard answered 6/12, 2023 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.