Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复测试名称的无效重竖琴视图?_C#_Nunit_Resharper - Fatal编程技术网

C# 如何修复测试名称的无效重竖琴视图?

C# 如何修复测试名称的无效重竖琴视图?,c#,nunit,resharper,C#,Nunit,Resharper,我将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

我将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
    }
 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)");
    }
private静态IEnumerable GetTests()
{
收益率回报率T(“foo.bA.)。。r@gmail.com", "foobar@gmail.com");
收益率回报率T(“foo.bA.)。。r@example.com,“foo.ba..”。。r@example.com");
收益率返回T(“user.name+标记+sorting@example.com“,”用户。name@example.com");
收益率T(“admin@mailserver1", "admin@mailserver1");
收益率回报率T(“aaaafoo.bA.)。。r@gmail.com", "aaafoobar@gmail.com");
}
私有静态TestCaseData T(字符串输入、字符串输出)
{
返回新的TestCaseData(输入、输出)
{
TestName=string.Format(“{0}”=>“{1}”,输入,输出)
};
}
[测试]
[TestCaseSource(name of(GetTests))]
公共void规范化(字符串输入、字符串输出)
{
//这里有一些测试
}
但当我在Resharper窗口中运行测试时,我看到我的名字被一些神秘的逻辑打断了:


是什么让我的名字变成这样的?如何解决这个问题?

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

例如,ReSharper运行xUnit理论没有这样的问题,NUnit的控制台运行程序似乎也不会返回任何对ReSharper行为有影响的奇怪信息

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

    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
    }
 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)");
    }
private静态IEnumerable GetTests()
{
返回新的TestCaseData(“foo.bA。。r@gmail.com", "foobar@gmail.comSetName(“GMail:删除点,将外壳标准化为较低(1)”);
返回新的TestCaseData(“foo.bA。。r@example.com,“foo.ba..”。。r@example.comSetName(“示例域:圆点完整,大小写标准化为较低”);
返回新的TestCaseData(“user.name+标记+sorting@example.com“,”用户。name@example.comSetName(“示例域:从+和后面的所有内容剥离的本地部分”);
返回新的TestCaseData(“admin@mailserver1", "admin@mailserver1SetName(“无论您在这里检查什么”);
返回新的TestCaseData(“aaaafoo.bA。。r@gmail.com", "aaafoobar@gmail.comSetName(“GMail:删除点,将外壳标准化为较低(2)”);
}
只要你没有在名字中使用点,你应该很好:


在Resharper窗口中是什么意思?在工具栏的
ReSharper->Windows
下有什么东西吗?我找不到任何证据,但我怀疑有某种逻辑将整个测试(包括名称空间和类)名称按
拆分,以显示简化的名称。我指的是在默认情况下运行测试时打开的窗口。它显示的是那些裁剪过的字符串,而不是正确的字符串。我不太清楚你的意思,我在运行测试时没有打开任何窗口。“单元测试会话”窗口。Resharper=>单元测试=>单元测试会话哇,谢谢你指出这一点!你也可以在他们的bug追踪器上创建bug记录单。谢谢