简体   繁体   English

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

[英]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.

相关问题 列出所有使用NUnit控制台运行程序的测试 - List all tests with NUnit console runner 我可以从命令行按顺序运行多个nunit测试吗?(使用nunit控制台运行程序) - Can I run multiple nunit tests sequentially from command line?(using nunit console runner) 使用NUnit Console Runner在文件夹下运行所有​​测试 - Use NUnit Console Runner to run all tests under a folder Bamboo nunit runner没有找到测试 - Bamboo nunit runner not finding tests NUnit 3控制台运行程序无法断言集合是有序的 - NUnit 3 console runner can't assert that collection is ordered NUnit 3.0 是否有 nunit-console-runner.dll? - Is there a nunit-console-runner.dll for NUnit 3.0? 运行测试时无法通过Nunit-console runner连接到网络驱动器 - Unable to connect to network drive through Nunit-console runner when running tests 从控制台运行器的多个程序集中并行运行 NUnit3 测试 - Run NUnit3 tests in parallel from multiple assemblies from console runner TeamCity - NUnit Console Runner 在使用 Kentico Fakes 时找不到所有单元测试 - TeamCity - NUnit Console Runner not finding all unit tests when using Kentico Fakes 使用 do.net test/nunit console runner 打印所有测试用例以及通过/失败 - Print all test cases along with passed/failed using dotnet test/nunit console runner
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM