Runner可以动态报告失败的测试吗

Runner可以动态报告失败的测试吗

本文介绍了NUnit Console Runner可以动态报告失败的测试吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nunit-console似乎像这样工作(参数:/nologo /wait /labels ...)

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.

通常这很好,但是我们也通过NUnit运行一些相互依赖的集成测试,有时一个测试挂起,因为先前的测试失败.

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.)

我真的希望让NUnit在开始下一个测试之前立即/即时报告失败的测试,包括详细的错误.这可能吗?

推荐答案

一种方法是在测试文件中包含拆解,该文件在每个测试完成时运行,然后输出测试的名称(如果有)失败.

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);
    }

这篇关于NUnit Console Runner可以动态报告失败的测试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:49