nunit3-vs-adapter icon indicating copy to clipboard operation
nunit3-vs-adapter copied to clipboard

Apparent test duplication when renaming tests

Open RobSwDev opened this issue 8 months ago • 2 comments

Not sure if this is an issue in NUnit, or in Visual Studio. Steps to repro are somewhat contrived, our real solution is much larger and has far more moving parts.

Start with a simple test

namespace Test.NS;

public class NUnitTest
{
    [TestCase("StringLiteral", true, TestName = $"Test")]
    public void Test(string stringValue, bool boolValue)
    {
        Assert.That(stringValue, Is.Not.Null);
        Assert.That(boolValue, Is.True);
    }
}

Initially, the tests shown in the explorer are as expected

Image

If I then change the TestName to Test1_StringLiteral_True and recompile, I see this:

  • The new name appears to have 2 versions of the test

Image

Sometimes there's an exception thrown by test discovery (I see this quite a bit - though the only reliable repro I can find is to change the namespace of the test)

[28/03/2025 11:57:18.054 AM] [Error] System.Collections.Generic.KeyNotFoundException: Unable to find UniqueTest Default,C:\Play\NUnitTests\bin\Debug\net9.0\NUnitTests.dll,Test.NS.NUnitTest.Test_NS_StringLiteral_True,,:cb40707d-1e0d-047e-e844-8d67fb3d6725
   at Microsoft.VisualStudio.TestStorage.TestStoreHierarchyTestNode.LookupUniqueTest(MergedTestIndex index)
   at Microsoft.VisualStudio.TestStorage.TestStoreHierarchyIndex.<>c__DisplayClass52_0.<GetUniqueTestsForNodes>b__0(TestStoreHierarchyTestNode ct)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at Microsoft.VisualStudio.TestStorage.TestStore.GetTestDetailsForNodes(Int32 viewId, IEnumerable`1 nodeIds, Int32 limit)+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.VisualStudio.TestWindow.Host.TestWindowStoreService.<>c__DisplayClass54_0.<QueryTestDetailAsync>b__0()
   at Microsoft.VisualStudio.TestWindow.Logging.ILoggerExtensions.CallWithCatchAsync[T](IInternalLogger log, Func`1 func, T defaultValue)

Sometimes the old name of the test is still shown in the explorer (can't currently repro) Very rarely, I can't get any of the tests to run at all, and have to close VS, do a git clean, and rebuild to recover (can't currently repro)

RobSwDev avatar Apr 02 '25 10:04 RobSwDev

I cant reproduce this:

Image

Code at : https://github.com/nunit/nunit3-vs-adapter.issues/tree/master/Issue1254

OsirisTerje avatar Apr 02 '25 13:04 OsirisTerje

Huh - that does repro for me. I have VS Version 17.12.5

Image

RobSwDev avatar Apr 02 '25 15:04 RobSwDev

Sorry for answering late here. I didn't notice your small "video".... my fault.

First, the Real Time test discovery gets in the way here. We have had several issues like this, see #1281 and #1256.

But even when turning that off, and then changing names, the old name seems to stick. I have stepped through the adapter, and verified that the response we have from the framework/engine only contain one test. Also confirmed that we onlysend one testcase event to the Test Explorer.

The but has to be in the Test Explorer. To me it looks like a cache issue since the old name is no longer in the current solution.

@Youssef1313 Comments ?

OsirisTerje avatar Oct 18 '25 19:10 OsirisTerje