Issue with Name format assignment in 3.12
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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