最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - Failed tests only showing the stacktrace, not the full logs - Stack Overflow

programmeradmin1浏览0评论

I have a pipeline running some C# Xunit tests. I run a dotnet test command where I specify --logger:trx. Then at the end of the agent job I have a Publish Test Results step.

When the pipeline is done, if I go to the "Tests" tab where it breaks down each test, for any failed test I can drill down to the default debug tab and see the error message and the stack trace. There's nothing listed under attachments though.

If I go to the Test Plans / Runs section for the test, I can download the trx file that gets produced. The trx file has the full output for each test so I'm not sure why it isn't listed as an attachment for each test. Is there something special I should be doing?

I have a pipeline running some C# Xunit tests. I run a dotnet test command where I specify --logger:trx. Then at the end of the agent job I have a Publish Test Results step.

When the pipeline is done, if I go to the "Tests" tab where it breaks down each test, for any failed test I can drill down to the default debug tab and see the error message and the stack trace. There's nothing listed under attachments though.

If I go to the Test Plans / Runs section for the test, I can download the trx file that gets produced. The trx file has the full output for each test so I'm not sure why it isn't listed as an attachment for each test. Is there something special I should be doing?

Share Improve this question edited Jan 29 at 21:01 pseudodev asked Jan 29 at 20:15 pseudodevpseudodev 1211 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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:

using 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:

using 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);
    }
}
发布评论

评论列表(0)

  1. 暂无评论