【问题标题】:How can I pass xunit test results to a custom attribute如何将 xunit 测试结果传递给自定义属性
【发布时间】:2018-03-23 04:11:22
【问题描述】:

我创建了一个 TestCaseAttribute,它有一个 After 方法。该属性接收test rail case Id和run Id,需要将结果发送到testrail。

问题是我无法配置如何将结果传递给 After 方法,或者如何从测试中更新属性属性。

按照我的属性类:

    [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");

    }
    }

}

【问题讨论】:

    标签: c# attributes xunit xunit.net


    【解决方案1】:

    不幸的是,我很确定 xUnit.net 不会在您正在查看/提议的级别上公开结果。

    您可以使用 TestRunner 覆盖来检测发现并运行测试类型,如下所示: https://github.com/xunit/samples.xunit/blob/master/ObservationExample/XunitExtensions/ObservationTestCaseRunner.cs

    在不更改测试的情况下管理全局后处理最接近的方法如下: https://github.com/xunit/samples.xunit/blob/master/TestRunner/Program.cs

    我猜你的真正答案要么在两者之间,要么在该组样本中的其他地方;那里有几乎所有可能的例子。

    【讨论】:

    • 谢谢我会尽量结合
    猜你喜欢
    • 2021-07-04
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多