[英]Can NUnit Console Runner report failed tests on the fly?
nunit-console
seems to work like this (params: /nologo /wait /labels ...
) nunit-console
似乎像这样工作(参数: /nologo /wait /labels ...
)
It outputs only the label for each test when a test is started, like so: 在开始测试时,它仅输出每个测试的标签,如下所示:
***** Our.Tests.Bla
... here come some Console.WriteLine
// Note that in case Our.Tests.Bla fails, nothing is reported here immediately
***** Our.Tests.Blub
... here come some Console.WriteLine
***** Our.Tests.Foo
... here come some Console.WriteLine
If any test fails, it reports the test failures only at the end of the complete run. 如果任何测试失败,则仅在完整运行结束时报告测试失败。
Normally this is fine, but we're also running some interdependent integration tests via NUnit, and sometimes one test hangs because a previous test failed. 通常这很好,但是我们也通过NUnit运行一些相互依赖的集成测试,有时一个测试挂起,因为前一个测试失败。
The problem is, when one test hangs, you do not see which / if any previous test failed, making it so much harder to quickly track down the problem. 问题是,当一个测试挂起时,您看不到哪个/如果先前的测试失败了,这使得快速查找问题变得更加困难。 (Especially when the tests are hanging on the test server machine, or maybe you only have a log of an aborted run.)
(特别是当测试挂在测试服务器计算机上时,或者也许您只有中止运行的日志。)
I would really prefer for NUnit to report failed tests, including the detailed error, on the fly / immediately before starting the next test. 我真的希望NUnit在开始下一个测试之前立即/即时报告失败的测试,包括详细的错误。 Is this possible?
这可能吗?
One way you could do this to have a Teardown in your tests file, which runs on each test completing, which can then output the name of the test if it failed. 一种执行此操作的方法是在测试文件中包含拆解,该拆解在每个测试完成时运行,如果测试失败,则可以输出测试的名称。
[TearDown]
public void TearDown()
{
var status = TestContext.CurrentContext.Result.Status;
if(status != TestStatus.Passed)
Console.WriteLine("Test Failed: {0}", TestContext.CurrentContext.Test.FullName);
}
Another question on here asked about having the console runner halt on the first error that it encountered . 此处的另一个问题询问有关让控制台运行程序在遇到的第一个错误时停止运行的问题 。
The /stoponerror
option is not what you asked for, but it's likely going to be about as good as you'll get. /stoponerror
选项不是您想要的,但是可能会和您得到的一样好。
This answer is based on Andrew's answer 该答案基于安德鲁的答案
Some classes changed in NUnit 3 so the TearDown
method needs to be changed too. NUnit 3中某些类已更改,因此
TearDown
方法也需要更改。 The result looks like this: 结果看起来像这样:
[TearDown]
public void TearDown()
{
var status = TestContext.CurrentContext.Result.FailCount;
if (status > 0)
Console.WriteLine("Test Failed: {0}\r\nMessage:\r\n{1}",
TestContext.CurrentContext.Test.FullName,
TestContext.CurrentContext.Result.Message);
}
you can use /labels. 您可以使用/ labels。 this will at least help you locate the failed test.
这至少可以帮助您找到失败的测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.