如何修复测试名称的无效 ReSharper 视图?
How to fix invalid ReSharper view of test names?
我将 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 window 中 运行 我的测试时,我看到我的名字被一些神秘的逻辑裁剪了:
是什么导致我的名字变成这样?如何解决?
看起来 ReSharper 在 运行 NUnit 参数化测试时在测试用例名称中遇到点问题:它只是丢弃点之前的任何内容。
例如,ReSharper 运行 xUnit 理论没有这样的问题,NUnit 的控制台运行器似乎也没有 return 任何似乎对 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)");
}
只要您不在名称中使用点,就可以了:
我将 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 window 中 运行 我的测试时,我看到我的名字被一些神秘的逻辑裁剪了:
是什么导致我的名字变成这样?如何解决?
看起来 ReSharper 在 运行 NUnit 参数化测试时在测试用例名称中遇到点问题:它只是丢弃点之前的任何内容。
例如,ReSharper 运行 xUnit 理论没有这样的问题,NUnit 的控制台运行器似乎也没有 return 任何似乎对 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)");
}
只要您不在名称中使用点,就可以了: