14

Error : No tests found to run - while debugging/running C# Unit test cases -- Visual studio 2017 15.5.1 not discovering test cases.

Framework Microsoft.NET framework 4.6.1

Added Test adapters as below MSTest.TestAdapter.1.2.0 MSTest.TestFramework.1.2.0

Test explorer not showing the test cases.

This started happening after upgrading visual studio. Some unit test projects test cases do not get discovered in the test explorer. When try to debug or run it says "No tests found to run."

I tried deleting project and recreating it again .. but didn't worked.

Output [4/3/2018 2:59:25 PM Informational] No tests found to run.

I have updated VS to 15.6.4 Deleting VS test cache files DEL %TEMP%\VisualStudioTestExplorerExtensions Restarted Visual studio

Test cases got discovered but not debugging

Neuron
  • 5,141
  • 5
  • 38
  • 59
Saurabh Raoot
  • 1,303
  • 3
  • 26
  • 31
  • 1
    NUnit? XUnit? MSTest? Did you install the proper adapters? Did you create any unit tests the way the test framework expects them? XUnit expect public classes and methods for example – Panagiotis Kanavos Apr 03 '18 at 09:59
  • Yes .. I have installed MSTest.TestAdapter.1.2.0 and MSTest.TestFramework.1.2.0 – Saurabh Raoot Apr 03 '18 at 10:02
  • For *which* framework? MSTest? Add the proper tags and post your code. Explain what you did *in the question itself*. – Panagiotis Kanavos Apr 03 '18 at 10:03
  • did you check [this](https://stackoverflow.com/questions/42861930/unit-tests-not-discovered-in-visual-studio-2017?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa)? There are many possibilities. Can you also share one of your test classes? – Francesco B. Apr 03 '18 at 10:15
  • Thanks for the link .. I tried few option ans half of the problem got resolved .. Test cases got discovered but still not able to debug... updated the question – Saurabh Raoot Apr 03 '18 at 10:32
  • Related post - [Visual Studio 15.8.1 not running MS unit tests](https://stackoverflow.com/q/51967866/465053) – RBT Apr 27 '21 at 07:31

12 Answers12

35

Problem

If I understand you correctly, this is something you observe:

when you run the tests, the following can be seen in the console:

[4/3/2018 2:26:13 PM Informational] ------ Run test started ------
[4/3/2018 2:26:14 PM Warning] No test is available in d:\...\UnitTestProject1.dll. Make sure that test discoverer & executors are 
registered and platform & framework version settings are appropriate and try
again.

and the test explorer shows:

no test found to run

What could have happened, and it happened to me a couple of times, that the test discovery is set up for another architecture than your currently set one.

Example

Your current configuration is x64

current configuration

but, the default test settings might have another one (e.g. x86):

default test settings

Solution

If you _align the test settings with your current architecture (x86 → x64), the tests should run.

successful run

Manual cleanups should not be necessary nowadays, if the solution is configured consistently

phuclv
  • 37,963
  • 15
  • 156
  • 475
Dmitry Ledentsov
  • 3,620
  • 18
  • 28
13

I had same problem, make sure you set TestClass to public !

[TestClass]
public class CSharp_JavaScript_ServerResponse_Test
{
}
Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64
luka_matkic
  • 197
  • 1
  • 3
6

I had may versions of the Nuget Package installed, I consolidated them into the latest one and it fixed the problem

I.e. instead of this:

MSTest.TestAdapter
MSTest.TestFramework

Use:

MSTest

"A meta package to simplify test projects."

rory.ap
  • 34,009
  • 10
  • 83
  • 174
Lord Darth Vader
  • 1,895
  • 1
  • 17
  • 26
4

The accepted answer didn't work for me in isolation but along with this it did:

  1. Exit MSVS
  2. Delete the .vs folder (you may lose a few settings related only to that solution)
  3. Restart MSVS
  4. From the accepted answer, ensure the Test -> Settings -> Def Arch-> matches the code
  5. Load playlist (if applicable)
  6. Build
  7. Test!
crokusek
  • 5,345
  • 3
  • 43
  • 61
4

As of today, me using NUnit @ VSCode and .NET Core 5.0 was missing Microsoft.NET.Test.SDK NuGet package.. As soon as I added it to ALL test assemblies (i.e.: all .csproj files in solution .sln), everything works fine. HTH to many who reach this far.

These PackageReferences are in my TestProject.csproj

<ItemGroup>
  <PackageReference Include="NUnit" Version="3.13.1"/>
  <PackageReference Include="NUnit.Console" Version="3.12.0"/>
  <PackageReference Include="NUnit3TestAdapter" Version="4.0.0-beta.2"/>
  <PackageReference Include="NUnitTestAdapter" Version="2.3.0"/>
  <PackageReference Include="NUnit.Extension.NUnitProjectLoader" Version="3.6.0"/>
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0-release-20210422-02"/>
</ItemGroup>
Sold Out
  • 1,321
  • 14
  • 34
2

Try clearing temp files located in the %TEMP% directory Delete folder : VisualStudioTestExplorerExtensions in %temp% directory.

Note: This path is generally at C:\Users\(yourusername)\AppData\Local\Temp

Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61
Shital Shah
  • 71
  • 1
  • 5
2

In my case, "Build -> Clean Solution" did the trick.

Amos Egel
  • 937
  • 10
  • 24
2

Also, make sure you have both MSTest.TestFramework AND MSTest.TestAdapter Nuget packages installed

MelOS
  • 595
  • 5
  • 10
0

I did below thing and it resolved my problem

  1. I have updated VS to latest version 15.6.4
  2. Deleting VS test cache files DEL %TEMP%\VisualStudioTestExplorerExtensions
  3. Restarted Visual Studio

Then test cases got discovered but not debugging.

It was giving error as:

Dependency finder domain): Loaded 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll'. Cannot find or open the PDB file.

and similar error for other DLLs as below:

C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\Microsoft.VisualStudio.TestPlatform.Common.dll'. Cannot find or open the PDB file.

So PDB is a debug information file used by Visual Studio. These are system DLLs, which you don't have debug symbols for.

Go to Tools->Options->Debugging->Symbols and select checkbox "Microsoft Symbol Servers", Visual Studio will download PDBs automatically.

Then I downgraded:

MSTest.TestAdapter.1.2.0 to 1.1.18

MSTest.TestFramework.1.2.0 to 1.1.18

Then restarted VS studio and rebuild.

Still got below error:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Then I set version to newVersion="4.0.0.0"

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.0.0.0" />
</dependentAssembly>

And it started debugging.

Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64
Saurabh Raoot
  • 1,303
  • 3
  • 26
  • 31
0

Guys

I was having the same problem, and fix it by adding the [TestClass] and [TestMethod], and got my Selenium Automated test library working on VS 2015.

Cheers,

[TestClass]
public class GigHubAutomatedTest
{

    [TestMethod]
    public void StartApplication()
    {

        using(IWebDriver googleDriver = new ChromeDriver())
        {

            // 1. Maximize the browser
            googleDriver.Manage().Window.Maximize();

            googleDriver.Navigate().GoToUrl("https://www.google.com/");

        }

    }

}
0

My issue was I was using async-await, and the return type was void. It needs to be Task. Changed this:

public async void MyTest()

To this:

public async Task MyTest()
dvdhns
  • 3,026
  • 2
  • 15
  • 11
0

You can get this error message if you make the mistake of right-clicking inside the editor then choosing Debug Test(s) when you are NOT in a unit test method (e.g. you have a method Foo() and you put a breakpoint in there and want to run the tests so they cause the breakpoint to be hit...nothing will happen if you choose Debug Test(s) while inside the body of Foo()...you have to go to Test Explorer and choose Debug or use the shortcut Ctrl+T,Ctrl+R).

Eric Mutta
  • 1,144
  • 1
  • 11
  • 15