question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Explicit tests are automatically run in Visual Studio 2019

See original GitHub issue

Hi,

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:34 (21 by maintainers)

github_iconTop GitHub Comments

7reactions
OsirisTerjecommented, Oct 26, 2019

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.

6reactions
sodabluecommented, Feb 4, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found