I am currently working on a solution that has currently 32 Unittests. I have been working with the resharper test runner - which works fine. All tests are running, all tests are showing the right test outcome.
However, the tests are not running when using the Visual Studio test explorer.
The Test Explorer is showing all unit tests, but once clicking on "Run All", all tests are getting greyed out and show no result of the test run:
[TestClass]
attribute declared[TestMethod]
attributeobj
, bin
, Debug
and Release
foldersI'd appreciate any hints which would explain this behaviour.
This question is related to
visual-studio
unit-testing
visual-studio-2012
resharper
For me restarting VS2017 did not work. I had to clean sln then found a file with tests that didn't run and run that file only. After that I did run all and it worked normal again.
In my case I had an async void
Method and I replaced with async Task
,so the test run as i expected :
[TestMethod]
public async void SendTest(){}
replace with :
[TestMethod]
public async Task SendTest(){}
Have tried many options with Visual Studio 2019 Version 16.4.6 and Microsoft.VisualStudio.TestTools.UnitTesting
, but for now the only way to run tests successfully was by invoking next command in console
dotnet test
Tests are discovered in Test Explorer but outcome is "Not Run".
Updating Visual Studio did not help.
Have resolved issue with "No test matches the given testcase filter FullyQualifiedName" by running updates to latest version for next packages:
Microsoft.NET.Test.Sdk
MSTest.TestAdapter
MSTest.TestFramework
I am using XUnit and was missing the xunit.runner.visualstudio
package. Installing it and my tests ran.
Install Nunit3TestAdapter
Nuget has solved this problem
In my case, it was because one test project in my solution had the MSTest.TestFramework and MSTest.TestAdapter nuget packages installed but the others did not. These packages were apparently not required to run tests until one project in the solution had them installed.
The issue was fixed by installing those packages on test projects missing them.
I had this issue and for me it was caused by having multiple Test Projects with different versions of :
Consolidating the nuget packages for the projects so they were the same resolved the issue for me.
Here it was the test project was not marked to be built:
Build -> Configuration Manager... -> check build for your test project
I can tell from your attributes that you're using MSTest. I had a similar issue: my tests were showing up in the Test Explorer, but when I would try to run them (either by choosing Run All or individually selecting them) they would not.
My problem was that I had created the unit test project manually from an empty .NET Standard Class Library project. I had installed the MSTest.TestFramework
NuGet package, but not the MSTest.TestAdapter
package. As soon as I installed the adapter package, they ran as expected.
Seems obvious in retrospect, but when you create unit test projects from a template, you take these things for granted.
For me having a property called TestContext in a base class was causing this behavior. For example:
[TestClass]
public abstract class TestClassBase
{
protected object TestContext { get; private set; }
}
[TestClass]
public class TestClass : TestClassBase
{
// This method not found
[TestMethod]
public void TestCase() {}
}
Clean-Rebuild
solution worked for me.
I had the same issue, but mine was resolved when I created a working copy on my actual desktop. The issue for me was because of the project folder was located on a network drive, and the dependencies were not able to load across the network drive for some reason. Hope this helps someone.
I had same symptoms.
Please ensure you have the proper Visual Studio extension installed via Tools - Extensions and Updates. In my case, I had to install XUnit and Specflow from the Online option.
Then clean the solution and rebuild it.
If that still doesn't help, clear your temp directory (search for %temp% in the Start menu search and delete all contents in Temp)
And then finally try uninstalling Resharper which finally fixed my problem.
I had to change my async test methods to return Task instead of void.
The tests were then active and runnable in Test Explorer.
Same issue. What was actually happening was that the test running was trying to discover tests in a web site project I have loaded (there was some jasmine specs for angular inside the site).
This was causing the runner to hang trying to load some NodeJS Container
Updating containers from Microsoft.NodejsTools.TestAdapter.TestContainer
I removed the website from the solution (obviously, just the solution, not deleting the website!)
I also had some corrupt configuration data that I had to clear out under the TestStore folder in the .vs directory.
After completing these two steps things magically started working again
It is worth mentioning that sometimes NUnit Test Adapter files get corrupted in user folder C:\Users[User]\AppData\Local\Temp\VisualStudioTestExplorerExtensions\NUnit3TestAdapter.3.8.0/build/net35/NUnit3.TestAdapter.dll on Windows 10 and that causes Test Explorer to stop working as it should.
Well i know i am late to the party, but logging my answer here , incase, someone is facing similar issue as mine. I have faced this issue many times. 90% it gets solved by these two steps
project > properties > Build > Platform target > x64 (x32)
Test -> Test Settings > Default Processor Architecture > X64 (x32)
However i found one more common cause. The Solution files often change developer systems and they start pointing to wrong MSTest.TestAdapter. Especially if you are using custom path of nuget packages. I solved this issue by
Opening the .csproj file in notepad.
Manually correcting reference to MSTest.TestAdapter in import instructions like this.
If your projects aren't all AnyCpu then you may also want to check that the following 2 settings match:
[Right click test project] -> properties -> Build -> Platform target - e.g. x64
[Main Menu] -> Test -> Test Settings -> Default Processor Architecture -> X64
I found that when these didn't match my test project would silently fail to run.
Try removing the [Ignore]
attribute from above the test method.
For me (not quite a solution) it was deselecting the .testsettings file in the Menu [Test]->[Test Settings]->[{current File}] to uncheck the currently used file.
In my case it starts so.
<TestSettings name="Local (with code coverage)" id="e81d13d9-42d0-41b9-8f31-f719648d8d2d" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Deployment>
<DeploymentItem filename="ConfigurationImportExportTest\Configurations\" />
<DeploymentItem filename="output\Debug\" />
</Deployment>
<Execution>
Apparently the DeploymentItem interferes.
because this was in the Output tab:
Warning: Test Run deployment issue: The assembly or module 'Microsoft.SqlServer.Management.SqlParser' directly or indirectly referenced by deployment item 'output\Debug\' specified by the test settings was not found.
.... more of the same
It does not tell me lots.
Seems like it has to do with the way that all projects put their compilation products in a common \output\Debug
folder
however that seems not to hinder it. It puts out another warning mentioning things like
A testsettings or runsettings file with `ForcedLegacyMode = TRUE or VSMDI files are not supported by MSTest-V2.
That seems to stop it.
In my case it worked to update the MSTest nuget packages. Could reproduce this problem even on blank MSTest project and updating the packages worked.
Yet another ridiculous case: it somehow happened that two projects in the same solution had the same ProjectId
- one of those was a test project and that confused Test Runner.
Removing and readding test projects to the solution changed the ProjectId
and fixed the issue.
I had same issue after update to Visual Studio 16.4.1. Go to Test explorer -> Settings button -> Processor Architecture for AnyCPU projects -> x64
What fixed it for me was upgrading the MS.Test nuget packages
If you are using NUnit rather than MSTest then you will need the NUnit Test Adapter Extension for Visual Studio 2012/2013.
Since I got here with this kind of error I post my problem/solution:
Symptoms:
Problem:
There was an error in the code that throw an exception inside another thread. All test assertions passed but it cancelled the test execution. I could see the error in the "Tests output" (NullException).
There are already a lot of answers to this question, but I had a different scenario and resolution.
We moved functionality of a type being tested from one class to a new class, and as such created a new test class, with the old test class ending up being empty.
Original:
Broken:
Fixed:
Clean the project, close Visual Studio, delete the TestResults folder, then restart VS, then rebuild the project. (This alone might fix your problem, but for me didn't suffice until a deleted the old test class.)
I found that in the project it was not referencing the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly. Instead, it was referencing Microsoft.VisualStudio.TestPlatform.TestFramework and Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions. When I removed those two references and added the reference to the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly the tests that were previously marked with the blue exclamation point suddenly became active and started working.
You can view the error-output of your test runner by opening the Output panel (view-->output) and choosing "tests" from the "Show output from" dropdown
Additionally, if you have Resharper installed you can open a test file and hover over the test-circle next to a test to get additional error info
Clicking that will bring you to a window with more detailed information. Alternatively, you can open that window by going to Extensions --> Reshaper --> Windows --> Unit Test Exploration Results
Had the same symptoms, in my case it was the dotnet core SDK version that was the problem.
The projects was targeting 2.2, and was able to build using 3.0. After installing newest 2.2 SDK version they were able to run.
What works for me is to delete the bin folder, then rebuild the project.
For me this was caused by a VS extension for measuring code coverage. It could not reference a particular assembly, and therefore would not run any of the tests. Tests would run fine from the command line using:
dotnet test
To solve this issue, you can opt to have ALL dependencies copied to your Test project debug folder. This ensures that any assemblies can be resolved, as "unused" assemblies are not removed. You can add the following to your Test projects .csprog file:
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
I use VS2019 with .Net 4.7. I installed NUnit extension v3, and changed the Test settings to use X64. My unit test project is Any CPU (would work if I changed it to x64). Now I can debug through my code.
I solved my problem completely different to any of the solutions in here:
Each of my tests made a call to a function which in turn called itself meaning it'd not terminate:
public GoogleIntent CreateIntent(BotPath botpath)
{
return CreateIntent(botpath);
}
I had a slightly different scenario, but this is the top Google result so I'll answer my issue too. I could run the tests but only about half of them actually ran, with no error output.
Eventually I debugged and stepped through all the tests, and came upon a Stack Overflow Error
when creating Test Instances of some models.
In the test instance methods, a child model created a parent and the parent created a child, which created an infinite loop. I removed the parent creation from the child, and now all my tests work!
Check what framework the tests are written against (e.g. nunit, xunit, VS test, etc.) and make sure you've got the correct test adapter/runner extension installed.
For me it was NUnit 3 Test Adapter that was missing and I confirmed the version number required by looking at the nunit.framework dependency version (select the .dll in the Dependencies tree in Solution Explorer and hit F4 to bring up the Properties window).
In my case, I had installed version 3.11.0
of both NUnit and NUnit3TestAdapter, but there were old references to version 2.6.4
, in the project file, that weren't removed with the new installation.
NUnit
and NUnit3TestAdapter
, this fixed the references in my project.PM> Update-Package NUnit -reinstall
...
PM> Update-Package NUnit3TestAdapter -reinstall
NUnit
and NUnit3TestAdapter
.PM> Uninstall-Package NUnit
...
PM> Uninstall-Package NUnit3TestAdapter
...
PM> Install-Package NUnit
...
PM> Install-Package NUnit3TestAdapter
I had different version of NUnit (3.11.0) and NunitTestAdapter (3.12.0) nuget packages. When I updated NUnit to 3.12.0, Visual Studio ran tests.
TLDR: Update the testing packages, look into the output -> test console
I struggled with this for a day and a half. so here's what I did to solve it:
Since all the packages were updated during the .net framework update, I started with the differences between the working and not working projects. The first clue was that all 3 projects were using: MSTest.TestAdapter and MSTest.TestFramework
Naturally I went to the -> Output console -> Test dropdown in VS 2019 and looked at the output. Nothing useful there.
Step one of the solution: Update the MSTest.TestAdapter and MSTest.TestFramework to version 2.0.0
Step two of the solution: Now the Output console -> Test dropdown output started showing one after the other, missing packages and wrong binding redirects
Step three of the solution: Manually add the missing packages. For me those were
Step 4 of the solution: Removed/Fixed the unnecessary binding redirects.
I hope this will help someone else.
I had the same problem in VS 2017. In my case it solved by restarting VS.
I had similar symptoms as OriolBG with the stack .Net Core/xUnit/FluentAssertions but for me updating the Microsoft.NET.Test.Sdk nuget package for the project did the trick.
This issue is also observed when the test method being run throws a StackOverflowException, making the test runner abort the test run, resulting in the output 0 tests run
.
To find the culprit and solve it put a break point at the start of both TestInitialize and TestMethod decorated methods, run the unit test in debug mode, proceed stepping over (F10) until the exception is thrown.
Upgrade your test project to the latest target framework version.
I was using Visual studio 2019 with target framework 4.5 whose support ended in 2016, jumping to 4.7 solved my problem.
I changed "Debug" to "Release" and it worked again (Any CPU.)
Source: Stackoverflow.com