[英]How can I pass xunit test results to a custom attribute
I have created a TestCaseAttribute, which has an After method. 我创建了一个具有After方法的TestCaseAttribute。 This attribute receives test rail case Id and run Id, and needs to send results to testrail.
此属性接收测试轨道案例ID和运行ID,并且需要将结果发送到测试轨道。
The issue is that I cannot configure how to pass the results to the After method, or how can I update the attribute properties from within the test. 问题是我无法配置如何将结果传递给After方法,或者如何从测试中更新属性。
Following my Attribute class: 跟随我的Attribute类:
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public class TestCaseAttribute : BeforeAfterTestAttribute
{
public ulong CaseId { get; private set; }
public ulong RunId { get; private set; }
public TestCaseAttribute(ulong caseId, ulong runId)
{
CaseId = caseId;
RunId = runId;
}
public string Result { get; set; }
public string Message { get; set; }
public override void After(MethodInfo methodUnderTest)
{
TestRail2.PostResult(RunId, CaseId, "Passed", message: "Test Passed");
}
}
}
I'm pretty sure xUnit.net does not expose the results at the level you are looking/proposing, unfortunately. 我很确定xUnit.net不会在您正在寻找/提议的级别上公开结果。
You can instrument the discovery and running with a TestRunner override for a test type like so: https://github.com/xunit/samples.xunit/blob/master/ObservationExample/XunitExtensions/ObservationTestCaseRunner.cs 您可以检测发现并使用TestRunner替代来运行测试类型,如下所示: https : //github.com/xunit/samples.xunit/blob/master/ObservationExample/XunitExtensions/ObservationTestCaseRunner.cs
The closest thing to manage global post-processing without changing your tests goes like so: https://github.com/xunit/samples.xunit/blob/master/TestRunner/Program.cs 在不更改测试的情况下管理全局后处理的最接近的方法是这样的: https : //github.com/xunit/samples.xunit/blob/master/TestRunner/Program.cs
I guess your real answer lies either in between the two or somewhere else in that set of samples; 我想您的真实答案是在这组样本中的两者之间或其他地方。 there's examples of pretty much anything that's possible in there.
这里有几乎所有可能的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.