Test generated by IFixtureBuilder is skipped the first time when its name changes
See original GitHub issueNUnit 3.13.2, NUnit3TestAdapter 4.2.1, Visual Studio 2022 Pro, 17.0.5, .NET Core 3.1
I have a custom IFixtureBuilder that generates tests with variable names. I noticed that under the VS test runner any name change is not picked up the first time, but only on the subsequent run. For test names that always change this means they never get run at all! All tests run every time under dotnet test or the ReSharper test runner, however.
To reproduce open NUnitDiscoveryNameChange.zip in VS 2022 and select Test, Run All Tests. The tests output window shows:
========== Starting test run ==========
NUnit Adapter 4.2.0.0: Test execution started
Running selected tests in C:\W ork\Bugs\NUnitDiscoveryNameChange\bin\Debug\netcoreapp3.1\NUnitDiscoveryNameChange.dll
NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
Running test: Test with fixed name - always runs
NUnit Adapter 4.2.0.0: Test execution complete
========== Test run finished: 1 Tests (1 Passed, 0 Failed, 0 Skipped) run in 300 ms ==========
Run it again and, depending on your luck, you might have the same output or “Test with random zero or one” may also run:
========== Starting test run ==========
NUnit Adapter 4.2.0.0: Test execution started
Running selected tests in C:\W ork\Bugs\NUnitDiscoveryNameChange\bin\Debug\netcoreapp3.1\NUnitDiscoveryNameChange.dll
NUnit3TestExecutor discovered 2 of 2 NUnit test cases using Current Discovery mode, Non-Explicit run
Running test: Test with fixed name - always runs
Running test: Test with random zero or one - sometimes runs: 0
NUnit Adapter 4.2.0.0: Test execution complete
========== Test run finished: 2 Tests (2 Passed, 0 Failed, 0 Skipped) run in 301 ms ==========
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Tips and Tricks | NUnit Docs
If RTD is enabled in Visual Studio, the tests will be displayed, but running will skip them. See explanation for the NonTestAssembly Attribute,...
Read more >Addin Replacement In The Framework
In NUnit 2.6, for example, it was possible to write an addin that defined tests based on the name of a method, e.g.:...
Read more >c# - Change name of NUnit test
I want my unit-tests based on NUnit framework named a bit more human readable in Visual Studio test explorer. For example instead of...
Read more >nunit.framework.xml
ITestAssemblyRunner Initializes a new instance of the class. The builder. The tree of tests that was loaded by the builder The test result,...
Read more >nunit.framework.xml
<param name="test">The test to which the filter is applied</param> ... This ensures that the same _values are generated each time the tests are...
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

The problem here is that the Test Explorer runs both a discovery and an execution. The dotnet test only runs execution. The discovery is so that the tree can be displayed after a build. The discovery phase will reflect over the types involved to detect their FQN names. Those names are the primary key for the display in the Test Explorer.
When that name is changing, the Test Explorer is not able to match what it found during discovery with what it found during execution.
This is the way that the Test Explorer have been working from day one. I am not sure if it would accept the names to be delivered only during execution. I have noticed that Rider does allow this, and trying your code on Rider, all three tests are run as they should.
It could be worth an experiment.
@OsirisTerje “Discover tests in real time from C# and Visual Basic .NET source files” was checked, yes. I tried unchecking it, but that did not change the behavior described in this issue (even after restarting VS). Tested on VS 17.4.5 now.