我正在尝试使用NUnit Runners 2.6.4在我的测试文件夹中运行所有测试程序集.我当前的命令如下所示:
/nologo /noshadow /framework:net-4.0 /xml:.\test\TestResults.xml .\test\*.Test.dll
Run Code Online (Sandbox Code Playgroud)
不幸的是,Nunit只抛出一个System.ArgumentException:路径中的非法字符.
无论如何我能做到这一点吗?
我有一个关于 nunit3-console 的问题。通过它运行测试时,我观察到生成的日志文件,例如内部跟踪和 nunit-agent 文本文件。
我能够使用 --trace=off 选项禁用内部跟踪的生成,但对于指定了 test .dll 的每次运行,我注意到生成了一个 nunit-agentNumber.txt 文件。
我的问题是,这是一个问题吗?更具体地说,对于 CI/CD 来说,是否有一个选项可以禁用它?或者至少在每次运行后清洁它。
我使用Travis CI设置了远程构建.这是我的配置文件:
language: csharp
solution: DungeonGen.sln
install:
- nuget restore DungeonGen.sln
- nuget install NUnit.Runners -OutputDirectory testrunner
script:
- xbuild DungeonGen.sln /p:TargetFrameworkVersion="v4.5.1" /p:Configuration=Stress
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Unit/Common/bin/Stress/DungeonGen.Tests.Unit.Common.dll
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Unit/Generators/bin/Stress/DungeonGen.Tests.Unit.Generators.dll
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Unit/Selectors/bin/Stress/DungeonGen.Tests.Unit.Selectors.dll
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Unit/Mappers/bin/Stress/DungeonGen.Tests.Unit.Mappers.dll
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Unit/Tables/bin/Stress/DungeonGen.Tests.Unit.Tables.dll
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Integration/Bootstrap/bin/Stress/DungeonGen.Tests.Integration.Bootstrap.dll
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Integration/Tables/bin/Stress/DungeonGen.Tests.Integration.Tables.dll
- mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Integration/Stress/bin/Stress/DungeonGen.Tests.Integration.Stress.dll
Run Code Online (Sandbox Code Playgroud)
但是,当它运行时,我得到以下异常:
$ mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Unit/Common/bin/Stress/DungeonGen.Tests.Unit.Common.dll
Cannot open assembly './testrunner/NUnit.Console.*/tools/nunit3-console.exe': No such file or directory.
The command "mono ./testrunner/NUnit.Console.*/tools/nunit3-console.exe ./Tests/Unit/Common/bin/Stress/DungeonGen.Tests.Unit.Common.dll" exited with 2.
Run Code Online (Sandbox Code Playgroud)
对于我尝试加载测试的每个DLL,都会重复此异常.根据Travis CI的文档 …
我有下面这个简单的测试方法.
[Test]
public async Task OneSimpleTest1()
{
var eightBall = new EightBall();
var answer = await eightBall.WillIWin();
Assert.That(answer, Is.True);
}
Run Code Online (Sandbox Code Playgroud)
测试类看起来像这样
public class EightBall
{
public Task<bool> WillIWin()
{
return new Task<bool>(() => true);
}
}
Run Code Online (Sandbox Code Playgroud)
我使用下面的命令在Nunit 2.6.2中运行测试.
nunit-console.exe EightBall.dll /framework:net-4.5
但是,测试似乎没有返回并永远挂起.是否有一种特殊的方法可以使用Nunit 2.6.2运行异步测试.我认为使用Nunit 2.6.2支持异步
我用 Nunit 2.6 编写了单元测试,但计划升级到 Nunit 3.6.1 ,但是我注意到 Nunit 3.6.1 出现了一个奇怪的问题(或者可能是我没有正确理解它)。问题出在 OneTimeSetUp() 上。
在 Nunit 2.6.3 中,我有 SetUpFixtureAttribute [SetUpFixture] 并在该 SetUpAttribute [SetUp] 中,它按我的预期工作,流程是
设置夹具.设置
测试夹具.设置
测试夹具.测试
测试夹具.TearDown
测试夹具.设置
测试夹具.测试
测试夹具.TearDown
设置夹具.TearDown
当我升级到 Nunit 3 时,我用 OneTimeSetUp 替换了 SetUpFixture 中的 SetUp(),运行代码后我得到了以下流程
测试夹具.设置
测试夹具.测试
测试夹具.TearDown
SetUpFixture.OneTimeSetUp
SetUpFixture.OneTimeTearDown
以下是我在我的机器上尝试的示例代码以及命令行输出
[SetUpFixture]
public class TestBase
{
[OneTimeSetUp]
//[SetUp]
public static void MyTestSetup()
{
Console.WriteLine(" ---------- Calling OneTimeSetUp ----------");
}
}
[TestFixture]
class TestClass : TestBase
{
[Test]
public void test()
{
Console.WriteLine("\n ....I'm inside TestClass.test() ...."); …Run Code Online (Sandbox Code Playgroud) 在NUnit控制台运行程序中,有一个控制台命令用于列出Visual Studio项目中的所有测试。有人知道吗?
我使用版本3.6.1。
我已经使用nunit在MSVS2013中成功运行我的C#单元测试,使用nunit GUI和nunit控制台.
对于前两个,我可以进入我的调试输出(Console.Write(...)).在MSVS2013中,可以通过在测试后单击"输出"链接查看,在GUI中,调试显示在"输出"窗口中.
当我使用nunit3-console.exe运行时,我只是得到摘要报告.我试着查看XML输出中的内容(在TestResults.xml中),但它只包含更多相同的摘要报告.
如何让我的调试也出现在屏幕上?
我的命令行如下所示:
nunit3-console.exe "c:\path\to\my\assebly.dll" --trace=Verbose --test=Regression.Tests.HelloWorld
Run Code Online (Sandbox Code Playgroud)
测试HelloWorld中有一行Console.Write("Hello World\r\n");,我想看到它出现在屏幕上(标准输出).