问题
nunit-console
seems to work like this (params: /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.
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. Is this possible?
回答1:
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);
}
回答2:
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.
回答3:
This answer is based on Andrew's answer
Some classes changed in NUnit 3 so the TearDown
method needs to be changed too. 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);
}
回答4:
you can use /labels. this will at least help you locate the failed test.
来源:https://stackoverflow.com/questions/26181046/can-nunit-console-runner-report-failed-tests-on-the-fly