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
PropertyAttributes to attach properties per test to the XML output. The example below assumes you really want to useConsole.WriteLineto produce string output, but you could always make your ownTestConsole.WriteLineor 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.Outto your "Output" property (again, you can use your ownTestConsolekind of class instead of using this attribute if you don't want to mess withConsole.Out).And your tests can just use
Console.WriteLinewhich will be captured per test:Which produces the following under
<results>in the NUnit XML output: