Explicit tests are automatically run in Visual Studio 2019
See original GitHub issueHi,
Since switching to Visual Studio 2019, tests marked as [Explicit] are run automatically when running all tests, such as when running all tests after build or manually telling Visual Studio to run all tests via the Test Explorer. This worked well on Visual Studio 2017, meaning that explicit tests were not run.
See the repo linked below for a minimal example.
Marking tests with [Ignore] still excludes the test from being run (although I do not seem to be able to run those tests even manually, but that’s another story)
- NUnit 3.12.0 and NUnit3TestAdapter 3.15.1
- Visual Studio 2019 Pro (16.2.5) and Visual Studio 2017 Enterprise (15.9.16)
- https://github.com/Stolpe/NUnitExplicitTest
- netcoreapp 2.1
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:34 (21 by maintainers)
Top Results From Across the Web
Explicit nunit tests are automatically run in Visual Studio 2019
"This issue is caused by a change in behavior in Visual Studio 2019, in how the test execution methods are being called.
Read more >Configure and use Live Unit Testing - Visual Studio
While you develop an application, Live Unit Testing automatically runs any affected unit tests in the background and presents the results and ...
Read more >Configure and use Live Unit Testing - Visual Studio
While you develop an application, Live Unit Testing automatically runs any affected unit tests in the background and presents the results and ...
Read more >Unit testing fundamentals - Visual Studio (Windows)
Learn how Visual Studio Test Explorer provides a flexible and efficient way to run your unit tests and view their results.
Read more >Live Unit Testing FAQ - Visual Studio (Windows)
Review these Live Unit Testing frequently asked questions, including supported frameworks, configuration, and customization.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This issue is caused by a change in behavior in Visual Studio 2019, in how the test execution methods are being called.
The adapter have two methods that the testhost can call, one “by sources” and one “by testcases”. The first one here was originally meant to be called from 1) command line 2) Visual Studio when running All Tests. The second one was meant to be called only from Visual Studio when something less than All Tests were selected.
Right now it seems that the second method is being called in all cases. I have so far not found that the 1st method is being called at all. I have tested from Visual Studo, from vstest.console and from dotnet test.
The issue here is that there is no way to deduce whether all tests are being run or not. There is no explicit information on what triggered the execution of the tests.
This means that all tests runs, regardless of how they are started, are perceived as a set of selected tests by the adapter, which means that they fulfill the demand set by the Explicit attribute.
The Product Group have been informed, and we’re waiting for further information from them on how this can be resolved.
I came up with a workaround/hack. I found the Ignored attribute works which means the runner can skip tests. I created my own DebugExplicitAttribute from the ExplicitAttribute which sets the runstate to ignored if the debugger isn’t attached. This allows me to run the test manually, but running all tests it will be skipped.
see this gist https://gist.github.com/sodablue/6941abcd6855e71b4393118c3e01bf2f