nunit / nunit/docs

Issue with Name format assignment in 3.12

Open
#324 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Dockerfile
Stars
600
Forks
158
Avg merge
16h 8m
Merged PRs (30d)
21

Description

According to the documentation for the "SetName" property:
"The SetName property of TestCaseData allow setting the format string for the individual test case. So long as no format specifiers are used in the name, there will be no change in how this works."

With a name being assigned as "String name", we would expect no hierarchical change in the name of the test. However, the {m} section is being removed regardless. We can manually add the {m} format specifier in each case, however this conflicts with provided documentation.

There is an additional issue can resulted as part of this problem, when test case data is shared across multiple tests. If multiple items end up sharing the same name (due to the {m} being missing) it causes the remaining test information to become statically listed within MSTest, and several other Test Runners (including the Resharper test runner).

Code to replicate is included:

    [TestFixture]
    public class DemoTestClass
    {
        [Test, TestCaseSource(nameof(GetTestCases))]
        public string objectUsedAsParamImpactsName(TestObjectClass obj)
        {
            Console.Write(obj.id);
            return obj.name;
        }

        private static IEnumerable<TestCaseData> GetTestCases()
        {
            var data = new TestObjectClass() {name = "Test Name", id = 1};
            var testCase = new TestCaseData(data);
            testCase.SetName("String used as name");
            testCase.Returns("Test Name");
            yield return testCase;
        }

        [Test, TestCaseSource(nameof(GetStringTestCasesData))]
        public string stringUsedAsParamShowsCorrectname(string str)
        {
            return str;
        }

        private static IEnumerable<TestCaseData> GetStringTestCasesData()
        {
            var testCase = new TestCaseData("Test Name");
            testCase.SetName("String used as name");
            testCase.Returns("Test Name");
            yield return testCase;
        }

        public class TestObjectClass
        {
            public string name;
            public int id;
        }
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SetName and TestCaseData documentation and the supplied DemoTestClass reproduction; compare the documented format behavior with the observed test names in NUnit and the named test runners. Done means determining whether the documentation or behavior is incorrect and updating the relevant documentation to accurately describe the {m} behavior and duplicate-name impact.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
documentation, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.