Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestContext.AddTestAttachment does not work on Linux environment with specified dotnet logger #494

Closed
kirill-d-lappo opened this issue Mar 26, 2018 · 3 comments

Comments

@kirill-d-lappo
Copy link
Contributor

kirill-d-lappo commented Mar 26, 2018

Summary

Test Attachments are not added to trx file after test run is done on linux environment.

Repro steps

  1. Create Nunit tests project with the only test, which adds some existing file to attachments.
  2. Build project and start test execution with command:
    dotnet vstest "/path/to/project.dll" /logger:"trx" /ResultsDirectory:./test-results /Diag:./diag/diag.main.log
  3. Wait until test execution is finished. Take a look at terminal messages, it says that 1 of 1 tests passed.
  4. Check created trx file

Expected result : the trx file contains section with a test attachment with correct file path;
Actual result : the trx file contains stderr section for the executed test:

 <StdErr>Failed to attach files from: Attachments&#xD;
Error Details: System.InvalidOperationException:System.InvalidOperationException: This operation is not supported for a relative URI.
   at System.Uri.get_LocalPath()
   at Microsoft.TestPlatform.Extensions.TrxLogger.Utility.Converter.ToResultFiles(AttachmentSet attachmentSet, Guid testResultExecutionId, TestRun testRun, String trxFileDirectory)
   at Microsoft.TestPlatform.Extensions.TrxLogger.Utility.Converter.UpdateTestResultAttachments(TestResult rockSteadyTestResult, TestResult testResult, TestRun testRun, String trxFileDirectory, Boolean addAttachments)</StdErr>

Analysis

I digged into adapter code, checked mstest logic and test execution logs(./diag/diag.main.log).
The reason of the problem is that adapter sends straigh file path to mstest's executor, without file:// URI schema.
So, for example, path /absolute/path/to/attachment.txt is a correct absolute path on linux environment, but mstest consider it as a relative path when it deserializes the data which was recieved from adapter. The path is deserialized without errors, but calling property .LocalPath(line 510) on relative uri causes exception from the repro steps.

I modified adapter code locally and added "file://" in the beginning of the file path right before attachment item creation. After that I built adapter dll and made my test project use that modified dll. Attachments were added to trx file without any error.

Other details

NUnit Version 3.10.1
NUnit3TestAdapter 3.10.0
dotnet sdk 2.1.301
vstest.console.exe 15.7.0
OS Ubuntu 18.04 LTS

Last Updated : 2018/07/04

@rprouse rprouse added the confirm We need a separate confirmation of this issue label Mar 26, 2018
@kirill-d-lappo
Copy link
Contributor Author

I updated the description as I looked into the problem a bit dipper than before.
I got the reason of the problem (more-less), but I'm not sure where it should be fixed.
My opinion is to add file:// schema right before attachment DTO for vstest.console.

I didn't check mstest code carefully and don't know how exactly mstest converts execution message from json to object.

@arybkin
Copy link

arybkin commented Jul 5, 2018

We have same problem on our side. Do you have any updates for this issue?

@OsirisTerje OsirisTerje added is:bug closed:done and removed confirm We need a separate confirmation of this issue labels Jul 7, 2018
@OsirisTerje OsirisTerje added this to the 3.11 milestone Jul 7, 2018
@kirill-d-lappo
Copy link
Contributor Author

kirill-d-lappo commented Jul 8, 2018

Tested on 3.11.0-ci-00893-pr-527 package, the bug is fixed, closing the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants