admin管理员组文章数量:1316304
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?
1 Answer
Reset to default 1When 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);
}
}
本文标签: netFailed tests only showing the stacktracenot the full logsStack Overflow
版权声明:本文标题:.net - Failed tests only showing the stacktrace, not the full logs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999209a2410663.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论