0 Total Tests - 0 passed,0 failed ,0 skipped even after having tests in the class
Asked Answered
C

15

18

While running unit test in Visual studio , i was getting 0 Total Tests - 0 passed,0 failed ,0 skipped even after having tests in the class.

Cichocki answered 5/9, 2020 at 13:7 Comment(0)
M
9

In Nunit, if there is an exception in loading test setup or execution it will result in above. From Visual studio menu open debug=>output and select Test window and see are there any exceptions thrown when tests are run. In my case in project1 i have nunit2 (refernce), in project2 i have nunit3 which referred project1 which is causing conflict and unable to execute.

if you resolve the exception it should work

Matsu answered 23/4, 2021 at 5:44 Comment(1)
In my case, the build configuration had the project un-selected for buildFederation
H
5

Installing Microsoft.NET.Test.Sdk package from nuget package manager solved my issue. I also have xunit and xunit.runner.visualstudio package installed.

Huntingdonshire answered 26/3, 2022 at 21:57 Comment(1)
Similar solution here: I'm using xunit but was missing xunit.runner.visualstudio nuget package. I didn't need to use Microsoft.NET.Test.Sdk.Gaudy
B
3

Check if you have runsettings file in your solution or if there is one selected under VS -> Test -> Configure Run Settings. If this is chosen, uncheck it. Remove the file. This fixed for me.

Bernhardt answered 31/12, 2020 at 15:46 Comment(0)
Q
3

Ensure the access modifier of the class is public instead of internal. If it is internal none of the [Fact]s in the class will register as tests within the Test Explorer, nor will they run.

Qualification answered 26/3, 2022 at 14:42 Comment(2)
By default the access modifier will be internal so we need to specifically decorate as publicCarpology
This gets me every time for some reason. Maybe there should be a warning under classes annotated with [Test Class] when you don't specify publicMaleki
B
2

For MSTest users - if you have a method marked with the [ClassInitialize] attribute, make sure that it is both public and static, and has a single parameter of type TestContext, otherwise the test file will not run.

[ClassInitialize]
public static void ClassInitialize(TestContext testContext)
{​​
    // initialization code...
}
Barcot answered 29/12, 2022 at 16:25 Comment(2)
Nice one.... Gave me the idea to check the attributes. In my case I had two [AssemblyInitialize] methods in two different classes. Thanks 🙌 For anyone looking for additional info - Method denoted with [AssemblyInitialize] attribute runs once when the assembly is loaded, but [ClassInitialize] runs once before any test methods in the class and [TestInitialize] runs before each test method in the class.Spectrochemistry
That was the problem in my case, Thanks!Countdown
C
1

Here in my case the issue was different . In VS Unit tests are being identified based on Test class. In my case , there were no access modifier for the class and which caused the issue .VS unable to identify the test methods for the particular class.

 class ControllerTests
{    
    public Controller _Controller;
   
    [TestMethod()]
}

After adding public to the class ,it worked fine. Public class ControllerTests {
public Controller _Controller;

    [TestMethod()]
}
Cichocki answered 5/9, 2020 at 13:7 Comment(1)
Great! In my case the issue was that the class was marked internal.Rosannarosanne
C
1

In Case anyone is still struggling with this, installing "MSTest.TestAdapter" solved my issue.

Consumable answered 11/8, 2021 at 9:10 Comment(1)
This package along with MSTest.TestFramework were already showing as installed for me. I then right clicked the solution and selected Restore Nuget Packages. Then Build->Clean Solution. Then Build->Rebuild Solution. The other answers alone did not work for me. After this, tests worked again. No idea why they were working minutes early then just stopped.Floriculture
A
1

For me a simple "Clean Solution" worked.

Amyamyas answered 4/2, 2022 at 20:40 Comment(0)
V
1

For C#/.NET Playwright:

I've seen this a couple times and my issue was that the return type of an async test method was void, instead of Task. It should be as follows:

    [TestMethod]
    public async Task TestMethod1()
    {
Varney answered 8/2, 2023 at 20:16 Comment(0)
T
1

I faced similar issue while running tests on local machine on Visual studio, following solution fixed the issue, Open Visual Studio, under Test -> Options, uncheck "Discover tests in real time from C# and Visual Basic .NET source files". Restart Visual studio and if needed rebuild solution.

Tatyanatau answered 29/8, 2023 at 8:22 Comment(0)
G
0

We ran into this issue trying to help a new developer on our team setup his development machine. The tests would show up in VS2022 TestExplorer, but running them would complete in a few ms, with the dreaded "0 passed, 0 failed, 0 skipped" result. The Output|Tests window didn't show any errors.

After a "Clean Solution", the tests would run.

Greaseball answered 2/3, 2023 at 18:45 Comment(0)
I
0

On VS with Nunit, this Library does the trick:

NuGet\Install-Package NUnit3TestAdapter -Version 3.7.0

enter image description here

Incarnation answered 12/4, 2023 at 0:37 Comment(0)
U
0

After checking all the troubleshooting steps suggested by others here I closed VS2022 and reopened my solution. Then it began to work. Moral of the story is that there is a large number of root causes to this problem. Sometimes Visual Studio is just cursed and needs to be exorcised of deamons.

Ultima answered 12/7, 2023 at 16:21 Comment(0)
W
0

If it was working already but suddenly stopped,and now giving error for xunit.runner.visualstudio in output windows then may be you can try below option shown in image atleast for me its solved. change runtime for xunit

Wilma answered 9/4 at 11:4 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Retainer
S
0

Error: "test run aborted 0 tests (0 passed 0 failed 0 skipped) run in 1 ms"

Solution: Install xunit.runner.visualstudio package

enter image description here

Selfgoverned answered 26/4 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.