简体   繁体   中英

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. The problem is that this file will not be generated by nunit until after it has ran through the teardown. Is there any way that I can terminate nunit in code using c# in the tear down?

NUnit generates it's XML output after the tests are finished. 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. For example, even if everything was OK up to that point, the TestFixtureTearDown might throw an exception and give you an error result. And of course you may have more than one fixture that has still to run at the time TestFixtureTearDown completes for a particular fixture.

The above is true in all versions of 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...

In NUnit V2, the XML output is generated by the console runner itself. 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. The difference is that NUnit 3 supports extensions to the engine. 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 also gives you the ability to create a new output format based on an xslt transform if that sort of thing appeals to you. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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