Skip to content

Apparent test duplication when renaming tests #1254

@RobSwDev

Description

@RobSwDev

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions