24

I am using the latest VS2017 version 15.6.4, NUnit3TestAdapter 3.10.0 and Nunit version 3.9.0.0.

When I try to run a unit test in Test Explorer the test are grayed out, when I right click and and run selected tests I see the following error: No test is available Here is how my test class looks

    [TestFixture]
    public partial class ListViewBOTest
    {
    [Test]
     public void TestSearch_DateTime()
      {
        Assert.AreEqual(1,0);
      }

    }

Here is a screenshot of my tests

Text from output:

[3/26/2018 10:53:55 AM Informational] ------ Run test started ------
[3/26/2018 10:53:55 AM Informational] NUnit Adapter 3.10.0.21: Test execution started
[3/26/2018 10:53:55 AM Informational] Running all tests in C:\Projects\MVPPlant\DEV\CMMSdg.Plant\CMMSdg.Plant\Sln.2010\CMMSdg.Plant.BusinessObjects.Test\bin\Debug\CMMSdg.Plant.BusinessObjects.Test.dll
[3/26/2018 10:53:56 AM Informational] NUnit failed to load C:\Projects\MVPPlant\DEV\CMMSdg.Plant\CMMSdg.Plant\Sln.2010\CMMSdg.Plant.BusinessObjects.Test\bin\Debug\CMMSdg.Plant.BusinessObjects.Test.dll
[3/26/2018 10:53:56 AM Informational] NUnit Adapter 3.10.0.21: Test execution complete
[3/26/2018 10:53:56 AM Warning] No test is available in C:\Projects\MVPPlant\DEV\CMMSdg.Plant\CMMSdg.Plant\Sln.2010\CMMSdg.Plant.BusinessObjects.Test\bin\Debug\CMMSdg.Plant.BusinessObjects.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[3/26/2018 10:53:56 AM Informational] ========== Run test finished: 0 run (0:00:01.0435303) ==========
Helen Araya
  • 1,886
  • 3
  • 28
  • 54
  • Just because I don't see it mentioned nor is it in the screenshot, I just want to double check that you have the `[TextFixture]` attribute at the top of your class that has the test methods in it? – Jake Smith Mar 26 '18 at 16:11
  • Yes I have. I just added a sample test. – Helen Araya Mar 26 '18 at 16:33
  • 1
    Update: Commenting one of the unit test classes in the solution fixed the problem. I still don't know what was wrong with that class.Still investigating.I will post the solution once I know the problem with that for sure. – Helen Araya Mar 28 '18 at 17:27
  • Possible duplicate of [Visual Studio 2015 or 2017 does not discover unit tests](https://stackoverflow.com/questions/29560011/visual-studio-2015-or-2017-does-not-discover-unit-tests) – Joakim M. H. Nov 26 '18 at 09:35
  • @JoakimM.H. that was asked for 2015.It is edited recently. – Helen Araya Nov 26 '18 at 14:03

14 Answers14

42

Make sure you have installed the NUnit3 Test Adapter from here

https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.NUnit3TestAdapter

Peter Morris
  • 20,174
  • 9
  • 81
  • 146
16

Can you check the following steps and see if it works?

  1. In the Visual Studio menu, go to Test > Test Settings > Default Processor Architecture and make a note if X86 is selected or X64
  2. Now go to the Build section in the Properties window of the project where the tests are written. Make sure the Platform target drop-down is selected to either Any CPU or at least it matches the architecture from the above step 1.

Now if you build the solution and try running those tests, you should see that they are now running.

hem
  • 2,100
  • 1
  • 10
  • 11
  • All my settings are as you described above. So this is not the problem. – Helen Araya Mar 27 '18 at 14:23
  • Ah... I don't know what else to suggest. I have a working Test Project using NUnit and by setting different Architecture I was able to produce the error like you're getting. Sorry, it didn't help you. – hem Mar 27 '18 at 15:10
  • Update: Commenting one of the unit test classes in the solution fixed the problem. I still don't know what was wrong with that class.Still investigating.I will post the solution once I know the problem with that for sure. – – Helen Araya Mar 28 '18 at 17:27
  • Okay, Where these unit classes in their own project? – hem Mar 28 '18 at 17:35
  • Yes all the unit test classes are in the same project. – Helen Araya Mar 28 '18 at 17:52
  • This corrected my problem as we had just recently changed the architecture from x86 to x64. Thanks! – FrankO Nov 29 '18 at 18:04
2

I found that my Build Events were wrong. Invalid copy command blew all my tests and half a day:

Copy C:\repo\Architecture\*.json $(ProjectPath)/Y
Copy C:\repo\Architecture\*.json $(TargetPath) /Y

instead of

Copy C:\repo\Architecture\*.json $(ProjectDir)/Y
Copy C:\repo\Architecture\*.json $(TargetDir) /Y
vich
  • 11,836
  • 13
  • 49
  • 66
2

I had the same problem as Amete Blessed and commenting out other Test methods made Test Explorer work and run my test

Cubelaster
  • 338
  • 4
  • 6
2

The messages in the Test Output window ("NUnit failed to load [assembly]", "No test is available...", etc.) can hide the underlying issue that's causing the runner to not load the test assembly. This includes hiding failures to load dependencies of the test assembly or the item under test.

If there's a test assembly that's showing up in the Test Explorer window, but the tests refuse to run, it's worth temporarily enabling fusion logging to see if any assembly binding errors occur when trying to run the tests.

Phil
  • 77
  • 6
2

After installing NUnit through nuget tests have appeared into Test Explorer but when I ran them I got "No test is available". Installing NUnit Test Adapter fixed the issue.

1

I had similar problem when using Xamarin.Forms. The solution was to install NUnit.XForms from NuGet and add

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />

to csproj file of the project where the tests are.

AGR
  • 321
  • 6
  • 8
1

What worked for me was to delete the ComponentModelCache folder located at %localappdata%\Microsoft\VisualStudio\<version>

Joakim M. H.
  • 424
  • 4
  • 14
0

You may have been a casualty of this problem that was (theoretically) resolved in 15.6.3. According to this answer, try deleting your %temp%\VisualStudioTestExplorerExtensions folder. That has resolved the issue for some other users.

Nick DeVore
  • 9,748
  • 3
  • 39
  • 41
  • Did you mean delete the whole folder VisualStudioTestExplorerExtensions or the contents of it? – Helen Araya Mar 26 '18 at 16:24
  • You can delete the whole folder. It gets auto created if it is missing – Nick DeVore Mar 26 '18 at 16:25
  • Just confirming you closed VS, deleted the folder, and then relaunched VS? If that doesn't work, what happens when you simply run it from the command line? If that fails, then VS is behaving properly and there's something else wrong. Maybe your code somehow? – Nick DeVore Mar 26 '18 at 16:36
  • Update: Commenting one of the unit test classes in the solution fixed the problem. I still don't know what was wrong with that class.Still investigating. – Helen Araya Mar 28 '18 at 17:27
  • I'm not sure why, but I had no folder named "VisualStudioTestExplorerExtensions". What worked for me was to delete the folder located at %localappdata%\Microsoft\VisualStudio\\ComponentModelCache – Joakim M. H. Nov 26 '18 at 09:29
0

Rather than using the Test Explorer, can you right click on the solution and Run Unit Tests from there?

0

Had the same problem. In my case I found that the NUnit test adapter will not be used by Test Explorer if your test project contains a reference to MSTest. Typically the Microsoft.VisualStudio.TestPlatform.TestFramework.dll but also check your .csproj file for "MSTest" and your packages.config file.

I discovered this by first enabling diagnostic logging for Visual Studio tests. This is found under "Tools" -> "Options" -> "Tests" -> "Logging Level".

In my log I found this entry:

[22/11/2018 10:36:42 Diagnostic] Project C:\Git\myProject\src\myProject.Tests\myProject.Tests.csproj references test adapter: MSTest.TestAdapter, version 1.1.18

Rob Powell
  • 1,367
  • 2
  • 13
  • 10
0

This is caused due to memory problem.

  • Clean object after test execution

Sample Code

private TestController testController;

[OneTimeSetUp]

public void TestSetup()

{

testController= new TestController();

}



[OneTimeTearDown]

public void TestCleanup()

{

testController= null;

}
  • Change test execution to 64 bits in settings

Test -> Test Settings -> Default Processors Architecture -> x64.

MrTesla
  • 99
  • 2
  • 9
0

I have also encountered the same issue.

Steps to resolve this issue -

 1. Install/Reinstall NUnit3TestAdapter package
 2. Delete Debug folder from the Bin
 3. Clean --> Build the project

Note - Also ensure all the packages are installed properly.

Now try to execute the tests.

atul parate
  • 760
  • 5
  • 5
0

I had the same issue, but it was fixed after installing "NUnit 3 TestAdapter version 3.16.1" via NuGet to my project.

M-A Charlotte
  • 325
  • 1
  • 3
  • 10