nunit.testlogger
nunit.testlogger copied to clipboard
Attachments are not added to xml document
Hello,
Inside my code I am adding an attachment:
TestContext.AddTestAttachment("TestResults1.txt", "Test Output1");
Then running test with dotnet vstest and specifying this logger with: /logger:"nunit;LogFilePath=LoginTest_TestResult.xml"
After test is finished, in LoginTest_TestResult.xml file I hope to find something like this:
<attachment>
<filePath>TestResults1.txt</filePath>
<description><![CDATA[Test Output1]]></description>
</attachment>
But there are no such fields! Is this a bug or something I am doing wrong?
@saska123 I just checked and it looks like logging of attachments has not been implemented, so I don't think you are doing anything wrong. I'm pretty new to this group and not sure if there are plans to add this or not.
This feature is not implemented yet. Here's the spec: https://docs.nunit.org/articles/nunit/technical-notes/usage/Test-Result-XML-Format.html#attachments
We should expose attachments from https://github.com/spekt/testlogger/blob/master/src/TestLogger/Core/TestRunConfiguration.cs via the TestRunCompleteWorkflow https://github.com/spekt/testlogger/blob/master/src/TestLogger/Core/TestRunCompleteWorkflow.cs
I slightly investigated how to add attachments. It's better to extend Spekt.TestLogger.Core.TestResultInfo with Attachments property (instead of extending TestRunConfiguration). This is due to a TestResult that provide access to attachments.
@codito what do you think about it?
@pantosha thank you for looking into this. I had missed it earlier, test attachments exist at both TestResult and TestRun level. See TestRunCompleteEventArgs. IIRC code coverage is a run level attachment, and the files added through TestContext.AddTestAttachment is reported at a individual TestResult. Adding to TestResultInfo definitely makes sense.
Additionally, the nunit xml spec mentions attachments to be part of test-suite and test-case. We'll need to see if the test-suite level entry is simply an aggregation.
From https://docs.nunit.org/articles/nunit/technical-notes/usage/Test-Result-XML-Format.html#attachments
<attachments>
Optional element that appears when files are attached to a test. Contains a list of <attachment> elements.
Containing Elements: <test-suite>, <test-case>
Contained Elements: <attachment>
Attributes None
Hello,
Are there any chances of adding support this feature in near future?
Yes, there is a plan to add support. We're open to PR contributions as well if anyone from the community wants to help 😄
Hi All, Is there any updates on that one?
Any new updates on this ?
Hi, no, I don't think there has been any work on this. As mentioned above we would be happy to take a PR.