简体   繁体   English

如何在拆卸中让nunit跑步者生成nunit-report.xml文件

[英]How to get nunit runners generated nunit-report.xml file in teardown

I currently run a suite of tests and in the TestFixtureTearDown I look for the "nunit-report.xml" and generate a webpage with the results. 我目前正在运行一组测试,并在TestFixtureTearDown中寻找“ nunit-report.xml”并生成一个包含结果的网页。 The problem is that this file will not be generated by nunit until after it has ran through the teardown. 问题在于,直到通过拆解后,nunit才会生成该文件。 Is there any way that I can terminate nunit in code using c# in the tear down? 有什么办法可以在拆解中使用c#终止代码中的nunit?

NUnit generates it's XML output after the tests are finished. 测试完成后,NUnit会生成其XML输出。 That makes sense, since the info to generate the report is not available till after the tests have all run. 这是有道理的,因为直到测试全部运行后才能生成报告的信息。

What you may not be realizing is that your TestFixtureTearDown is part of your test. 您可能没有意识到的是TestFixtureTearDown是测试的一部分 For example, even if everything was OK up to that point, the TestFixtureTearDown might throw an exception and give you an error result. 例如,即使到目前为止一切正常, TestFixtureTearDown可能会引发异常并为您提供错误结果。 And of course you may have more than one fixture that has still to run at the time TestFixtureTearDown completes for a particular fixture. 当然,对于特定的灯具,在TestFixtureTearDown完成时,您可能还有多个灯具仍在运行。

The above is true in all versions of NUnit. 上面的内容在所有版本的NUnit中都是正确的。 What you may do about it varies between NUnit V2 and NUnit 3. Sincde you use the term TestFixtureTearDown , I'll start by assuming an older version of NUnit... 在NUnit V2和NUnit 3之间,您可能会做些什么。如果您使用术语TestFixtureTearDown ,那么我将假定使用较旧版本的NUnit ...

In NUnit V2, the XML output is generated by the console runner itself. 在NUnit V2中,XML输出由控制台运行程序本身生成。 It's not available until after the runner exits. 直到跑步者退出后才可用。 If you want to write code to generate a report from it, you have to write a separate program, which you run after the test completes. 如果要编写代码以从中生成报告,则必须编写一个单独的程序,该程序在测试完成后运行。

In NUnit 3, the output is created by the engine but still on request of the console runner. 在NUnit 3中,输出是由引擎创建的,但仍应控制台运行程序的请求。 The difference is that NUnit 3 supports extensions to the engine. 区别在于NUnit 3支持引擎扩展。 You can write code as a report writer extension and invoke it from the command-line. 您可以将代码编写为报告编写器扩展,然后从命令行调用它。 With the proper extension, written by you, you might for example invoke NUnit with nunit3-console mytest.dll --result:myreport.html;format:myhtml 使用您编写的适当扩展名,您可以例如使用nunit3-console mytest.dll --result:myreport.html;format:myhtml调用NUnit nunit3-console mytest.dll --result:myreport.html;format:myhtml

NUnit3 also gives you the ability to create a new output format based on an xslt transform if that sort of thing appeals to you. NUnit3还使您能够基于xslt转换创建一种新的输出格式(如果您喜欢的话)。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM