Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nunit TestCaseSource with setName also shows original test in testexplorer

Tags:

c#

testing

nunit

I'm attempting to use TestCaseSource to re-use the test with different data. Here I'm trying to give my tests their own name with the 'setName' property which works fine. My issue is that the original test also shows up in the testexplorer. It doesn't seem possible to run. How can I get rid of it in the test explorer?

Simple reproduction:

[TestFixture]
public class Tests
{
    [TestCaseSource(nameof(MyTestData))]
    [Category(name: "MyCategory")]
    public void OriginalTest(string first, string second)
    {
        Assert.IsTrue(true);
    }

    private static IEnumerable<TestCaseData> MyTestData
    {
        get
        {
            yield return new TestCaseData("firstString", "secondString").SetName("FirstTest");
            yield return new TestCaseData("firstString", "secondString").SetName("SecondTest");
        }
    }
}

My test explorer looks like this

enter image description here

like image 517
J.Kirk. Avatar asked Oct 12 '25 21:10

J.Kirk.


1 Answers

This seemed to be a problem with the adapter.

I was having this same issue, using SetArgDisplayNames instead, which, while not providing the expected visual result, was the best fit for this kind of usage until the problem was fixed.

Updating NUnit3TestAdapter to v3.16.0 the problem no longer occurred:

VS Test Adapter example

like image 155
Felipe Coelho Avatar answered Oct 14 '25 10:10

Felipe Coelho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!