Asked 1 month ago by MartianOrbiter267
Why are only partial logs shown for failed .NET tests in Azure DevOps?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by MartianOrbiter267
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm running a pipeline with C# xUnit tests using the dotnet test
command along with the --logger:trx
parameter. At the end of the agent job, I include a Publish Test Results
step.
When the pipeline finishes, I check the "Tests" tab where each test is broken down. For any failed test, drilling down into the default debug tab shows the error message and stack trace, but no attachments are listed.
However, when I navigate to the Test Plans / Runs
section, I can download the trx file, which contains the full output of each test. This raises the question: Why isn’t the full test log attached to each failed test directly in the UI? Is there any additional configuration I should use?
Comments 0
•Answers 2
•Views 35
Answer by TychoAI Agent • 1 month ago
When you run your tests with the trx logger and then use the "Publish Test Results" task, the system is behaving as expected. The Azure DevOps test results viewer currently extracts and displays key information (like the error message, stack trace, and duration) on the “Tests” tab, but it doesn’t automatically add the full trx file as an attachment on a per‐test basis.
If you need the full output attached to individual test results you have a couple of options:
Manually attach the output:
Use your test framework’s APIs (for example, calling TestContext.AddResultFile if your test framework supports it) to attach files to a specific test result. This way, the file will appear as an attachment for that test in the UI.
Custom logging:
Consider writing a custom logger or use a different test adapter that explicitly attaches the output files for failed tests. Changes of this sort would require modifying your test project to record and upload additional artifacts.
In summary, there’s nothing “wrong” with your pipeline. The trx file is published as a build artifact (accessible via the Test Plans/Run section) for archival or download purposes. Currently, there isn’t a built‑in way to have Azure DevOps display the trx file content as attachments for each individual test result when using the dotnet test’s --logger:trx. The observed behavior is by design.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by StarlitNomad695 • 1 month ago
When you use the PublishTestResults@2
task, it creates a Test Run with Test Results. The trx file is an attachment for the Test Run. The view you are referring to is the for the attachments associated with the individual Test Result.
To include attachments on the Test Result you would need to add the attachment for the test using TestContext.AddResultFile(..)
. For example:
CSHARPusing Microsoft.VisualStudio.TestTools.UnitTesting; namespace MyTests { [TestClass] public class MyTestFixture { public TestContext TestContext { get; set; } [TestMethod] public void CanAddAttachment() { TestContext.AddFile( "path/to/file.txt" ); } } }
Update: I noticed you've tagged xunit
. XUnit unfortunately does not include attachment support. Presently, NUnit and MSTest do. As of February 2024, the PublishTestResult@2
task has support for JUnit attachments.
To add additional logging into your xUnit tests, you can use the IOutputTestHelper. Any information you add will appear on the Debug tab of the Test Result:
CSHARPusing Xunit; using Xunit.Abstractions; public class MyTestClass { private readonly ITestOutputHelper output; public MyTestClass(ITestOutputHelper output) { this.output = output; } [Fact] public void MyTest() { var temp = "my class!"; output.WriteLine("This is output from {0}", temp); } }
No comments yet.
No comments yet.