问题
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. Now a coworker told me, that the tests are not running on his machine using the Visual Studio test explorer. They are not working either on my machine, so i can exclude some local missing files or something.
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:
- All test classes are public
- All test classes are having the
[TestClass]
attribute declared - All test methods are using the
[TestMethod]
attribute - Both the productivity code and the test projects are targeting .NET 3.5.
- I have already tried to clean build my solution, and / or delete all
obj
,bin
,Debug
andRelease
folders
I'd apprechiate any hints which could cause such a behaviour.
回答1:
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.
回答2:
I had the same problem in VS 2017. In my case it solved by restarting VS.
回答3:
If you are using NUnit rather than MSTest then you will need the NUnit Test Adapter Extension for Visual Studio 2012/2013.
回答4:
I had to change my async test methods to return Task instead of void.
The tests were then active and runnable in Test Explorer.
回答5:
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).
回答6:
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:
Symptoms
- 5 Unit test projects, all discoverable in TestExplorer
- 2 out of 5 executed properly
- 3 stating not run at all
- The problem started after a .net framework update
Investigation
Since all the packages were updated during the .net framework update, I started with the differences between the workin 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 usefull 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
- System.Runtime.Extentions
- System.Reflection
- Maybe some more that I'm missing
Step 4 of the solution: Removed/Fixed the unessecary binding redirects.
I hope this will help someone else.
回答7:
Clean-Rebuild
solution worked for me.
回答8:
I had this issue and for me it was caused by having multiple Test Projects with different versions of :
- MSTest.TestAdapter
- MSTest.TestFramework
Consolidating the nuget packages for the projects so they were the same resolved the issue for me.
回答9:
Had same issue after clean install of VS 2019. Tests are found but not run with "Unexpected error occurred". Fixed by setting up x64 instead of x86 which was selected by default.
回答10:
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.
回答11:
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.
回答12:
What fixed it for me was upgrading the MS.Test nuget packages
回答13:
Install Nunit3TestAdapter
Nuget has solved this problem
回答14:
Setting Processor Architecture for AnyCPU Projects in Test Explorer fixed my issue! See screenshot above.
回答15:
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(){}
回答16:
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.
回答17:
Here it was the test project was not marked to be built:
Build -> Configuration Manager... -> check build for your test project
回答18:
Since I got here with this kind of error I post my problem/solution:
Symptoms:
- Not all tests running, but they didn't depend per project, just some of them were executed.
- All executed ones were green.
- Tech stack: dotnet core / XUnit / FluentAssertions
- All tests detected and updated if it changed.
- By selection or running "Not runned tests" several times they could be executed.
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).
回答19:
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.
回答20:
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
回答21:
For me solution was to change the Resharper Unit Testing settings "Default platform architecture" to "x64"
回答22:
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.
回答23:
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.
回答24:
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.
回答25:
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() {}
}
回答26:
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.
回答27:
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.
回答28:
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.
回答29:
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.
回答30:
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
来源:https://stackoverflow.com/questions/23363073/tests-not-running-in-test-explorer