I have been trying to figure out a way to add some string output to NUnit test results. I did some research and came across this, but this is not what I want. I want to write the output to the result xml
generated by NUnit, but I cannot find a way to do it. Please suggest!
I aware that NUnit 3 will have a mechanism called TextContex to accomplish something similar, but I am using 2.6.3.
You could take advantage of
PropertyAttribute
s to attach properties per test to the XML output. The example below assumes you really want to useConsole.WriteLine
to produce string output, but you could always make your ownTestConsole.WriteLine
or something if you don't want to mess with the console output.E.g. this attribute says to attach an "Output" property to each test it's declared on:
And this attribute says to redirect
Console.Out
to your "Output" property (again, you can use your ownTestConsole
kind of class instead of using this attribute if you don't want to mess withConsole.Out
).And your tests can just use
Console.WriteLine
which will be captured per test:Which produces the following under
<results>
in the NUnit XML output: