Is it possible to customize NUnit XML Output

给你一囗甜甜゛ 提交于 2019-12-10 13:28:25

问题


I'm looking at NUnit XML output right now, and wonder if it's possible to generate the output for failures only.

I mean, if a test passes ok, no XML output gets generated for it at all.

(UPDATE: XSLT is not an option here. I don't want XML output for passed tests at all: if I don't need the details about the passed tests, I don't want the system to spend time generating those details.)

The idea is, XML output tend to be quite large if you have a lot of tests, but 80% of the time you're after failures anyway. For such cases, I'd like to run my tests in such a way that only info on failures get generated.


回答1:


You can specify an XSLT file when you run the NUnit console runner to customise the generated file:

nunit-console /transform:failures.xslt nunit.tests.dll

The default XML file is generated using this XSLT file which can be easily modified to report only failures.




回答2:


Posted this question to NUnit Google Group, and Charlie Poole confirmed that there's no such option.




回答3:


I cannot guarantee if it works, but possibly you can write your own addin to achieve what you want. If you hook into the extension point "EventListeners" with your addin, your method TestFinished(TestResult tr) which you'll have to implement will get called whenever a test is finished. Just readout the result and set the property WriteResultEntry to true only for failed tests. Well i'm not sure if Charlie has implemented the latter property but if not, your addin could still create your own NUnit resultfile just for the failed tests.

/// <summary>
/// Test finished.
/// </summary>
/// <param name="result">The result.</param>
public void TestFinished(TestResult result)
{
   if (!result.IsFailure)
   {            
      result.WriteResultEntry = false;
   }
}

If there's no such property WriteResultEntry, ask Charlie to implement it or create your own result report by only writing output when result.IsFailure is true.



来源:https://stackoverflow.com/questions/2222203/is-it-possible-to-customize-nunit-xml-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!