Search code examples
unit-testingxunit.netxunit2

Discover Tests Runs Twice in xUnit


I have my solution setup whereby there is one xUnit test project/assembly configured within that solution that has an xUnit desktop runner.

When I run the tests of this solution by running "Run All" in the Test Explorer window, I see the following output:

------ Discover test started ------
[xUnit.net 00:00:00.6641444]   Discovering: Namespace.Testing
[xUnit.net 00:00:01.7346388]   Discovered:  Namespace.Testing
========== Discover test finished: 255 found (0:00:02.2705091) ==========
------ Run test started ------
[xUnit.net 00:00:00.7718801]   Discovering: Namespace.Testing
[xUnit.net 00:00:01.9540699]   Discovered:  Namespace.Testing
[xUnit.net 00:00:02.6006763]   Starting:    Namespace.Testing
[xUnit.net 00:00:13.1270643]   Finished:    Namespace.Testing
========== Run test finished: 255 run (0:00:17.5635971) ==========

There appears to be a "Discover test" step and a "Run test" step being executed, where the "Discovering" and "Discovered" steps are being executed for each step, making it appear that they run twice.

I am curious if this is being run by design or if I have an errant setting somewhere that is causing this behavior. It seems to me (or would be expected) that the "Discovering/Discovered" would only occur once per run. As you can see, it is adding an additional 2 seconds to each run and I would like to avoid that if possible.


Solution

  • First "Discovering" comes from the "Test Explorer" trying to discover tests.

    And the second one is from the "XUnit Visual Studio Runner".

    When running test on e.g. TFS Server, it will only run "Discovery" once.