【发布时间】:2026-01-01 04:05:01
【问题描述】:
我可以从命令行运行一个单独的测试用例,它采用单个字符串值,没有任何问题:
例如/run:Namespace.Class.Method("my input string")
但是对于数字输入,相同的过程似乎对我不起作用
例如:/run:Namespace.Class.Method(1,2,3)
输出将正确的输入列为“要运行的测试”,但实际上并未运行任何测试
编辑:
进一步研究,问题似乎在于测试需要多个参数。使用以下测试文件:
namespace GetTestsProj
{
[TestFixture]
class NunitConsoleTest
{
[TestCase(1,2,3)]
[Test, Description("A simple test with parameterized numeric inputs")]
public void TestNumeric(int a, int b, int c)
{
Assert.AreEqual(c, a + b);
}
[TestCase("My String")]
[Test, Description("A simple test with parameterized string input")]
public void TestSingleString(string a)
{
Assert.AreEqual("My String", a);
}
[TestCase("String1", "String2")]
[Test, Description("A simple test with parameterized numeric inputs")]
public void TestTwoStrings(string a, string b)
{
Assert.AreEqual("String1", a);
}
}
}
调用 nunit-console.exe /run:GetTestsProj.NunitConsoleTest GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll 正确运行所有 3 个测试用例
nunit-console.exe /run:GetTestsProj.NunitConsoleTest.TestNumeric GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll 调用正确运行了 1 个测试用例
nunit-console.exe /run:"GetTestsProj.NunitConsoleTest.TestSingleString(\"My String\")" GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll 调用正确运行了 1 个测试用例
但是,调用 nunit-console.exe /run:GetTestsProj.NunitConsoleTest.TestNumeric(1,2,3) GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll 运行 0 个测试用例
同样,nunit-console.exe /run:"GetTestsProj.NunitConsoleTest.TestTwoStrings(\"String1\",\"String2\")" GetTestsProj\GetTestsProj\bin\debug\GetTestsProj.dll 调用运行 0 个测试用例
虽然 nunit 似乎可以正确识别输入 /run:
Selected test(s): GetTestsProj.NunitConsoleTest.TestNumeric(1,2,3)
Tests run: 0, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
和
Selected test(s): GetTestsProj.NunitConsoleTest.TestTwoStrings("String1", "String2")
Tests run: 0, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0156256 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
这都是使用 NUnit 2.5.9.10348
我对这是用户错误还是不支持的功能感兴趣。这对我正在尝试做的事情非常有用。
【问题讨论】:
-
由于这可能是一个错误,我已将其提交给 nunit:link。