Issue with Name format assignment in 3.12

未关闭
#324 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
csharp

调研方向

从 SetName 和 TestCaseData 文档以及提供的 DemoTestClass 复现开始;将文档中说明的格式行为与在 NUnit 和所提及的测试运行器中观察到的测试名称进行比较。完成的标准是确定文档或行为是否不正确,并更新相关文档,以准确描述 {m} 的行为以及重复名称的影响。

由索引模型根据 Issue 内容生成。

描述

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;
        }
    }
主要语言
Dockerfile
星标
601
派生
159
平均合并
22 小时 18 分钟
30 天内合并 PR
6

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nunit/docs 的其他 Issue

查看 nunit/docs 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。