gpt4 book ai didi

c# - 如何修复测试名称的无效 ReSharper View ?

转载 作者:行者123 更新时间:2023-11-30 12:20:08 25 4
gpt4 key购买 nike

我将 NUnit (3.8.1) 与 Resharper (2018.2.3) 一起使用,如下所示:

    private static IEnumerable<TestCaseData> GetTests()
{
yield return T("foo.bA..r@gmail.com", "foobar@gmail.com");
yield return T("foo.bA..r@example.com", "foo.ba..r@example.com");
yield return T("user.name+tag+sorting@example.com", "user.name@example.com");
yield return T("admin@mailserver1", "admin@mailserver1");
yield return T("aaaafoo.bA..r@gmail.com", "aaafoobar@gmail.com");
}

private static TestCaseData T(string input, string output)
{
return new TestCaseData(input, output)
{
TestName = string.Format("'{0}' => '{1}'", input, output)
};
}

[Test]
[TestCaseSource(nameof(GetTests))]
public void Normalize(string input, string output)
{
//some test here
}

但是当我运行我的测试时,在 Resharper 窗口中,我看到我的名字被一些神秘的逻辑裁剪了:

invalid resharper test view

是什么导致我的名字变成这样?如何解决?

最佳答案

看起来 ReSharper 在运行 NUnit 参数化测试时遇到测试用例名称中的点问题:它只是丢弃点之前的任何内容。

例如,运行 xUnit 理论的 ReSharper 就没有这样的问题,NUnit 的控制台运行器似乎也不会返回任何似乎对 ReSharper 行为有影响的奇怪内容。

要解决此问题,您可以使用 SetName() 方法为每个测试用例提供一个描述性名称,如下所示:

 private static IEnumerable<TestCaseData> GetTests()
{
yield return new TestCaseData("foo.bA..r@gmail.com", "foobar@gmail.com").SetName("GMail: dots removed, casing normalized to lower (1)");
yield return new TestCaseData("foo.bA..r@example.com", "foo.ba..r@example.com").SetName("Example domain: dots intact, casing normalized to lower");
yield return new TestCaseData("user.name+tag+sorting@example.com", "user.name@example.com").SetName("Example domain: local part stripped from + and everything that follows");
yield return new TestCaseData("admin@mailserver1", "admin@mailserver1").SetName("Whatever you're checking here");
yield return new TestCaseData("aaaafoo.bA..r@gmail.com", "aaafoobar@gmail.com").SetName("GMail: dots removed, casing normalized to lower (2)");
}

只要您不在名称中使用点,就可以:

enter image description here

关于c# - 如何修复测试名称的无效 ReSharper View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53258199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com