nunit.testlogger icon indicating copy to clipboard operation
nunit.testlogger copied to clipboard

Attachments are not added to xml document

Open saska123 opened this issue 6 years ago • 9 comments

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 avatar Sep 10 '19 08:09 saska123

@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.

Siphonophora avatar Sep 10 '19 21:09 Siphonophora

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

codito avatar Jan 28 '21 06:01 codito

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 avatar May 22 '21 16:05 pantosha

@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

codito avatar May 25 '21 09:05 codito

Hello,

Are there any chances of adding support this feature in near future?

StefanCecerko avatar Dec 08 '21 16:12 StefanCecerko

Yes, there is a plan to add support. We're open to PR contributions as well if anyone from the community wants to help 😄

codito avatar Dec 17 '21 15:12 codito

Hi All, Is there any updates on that one?

NazarHomeniuk avatar Aug 18 '22 12:08 NazarHomeniuk

Any new updates on this ?

bheemreddy181 avatar Nov 29 '22 18:11 bheemreddy181

Hi, no, I don't think there has been any work on this. As mentioned above we would be happy to take a PR.

Siphonophora avatar Nov 30 '22 01:11 Siphonophora