Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将xunit测试结果传递给自定义属性_C#_Attributes_Xunit_Xunit.net - Fatal编程技术网

C# 如何将xunit测试结果传递给自定义属性

C# 如何将xunit测试结果传递给自定义属性,c#,attributes,xunit,xunit.net,C#,Attributes,Xunit,Xunit.net,我创建了一个TestCaseAttribute,它有一个After方法。此属性接收testrail案例Id和运行Id,并需要将结果发送到testrail 问题是我无法配置如何将结果传递给After方法,或者如何从测试中更新属性属性 以下是我的属性类: [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] public class TestCaseAttribute : BeforeA

我创建了一个TestCaseAttribute,它有一个After方法。此属性接收testrail案例Id和运行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");

    }
    }

}

不幸的是,我非常肯定xUnit.net不会以您正在查看/建议的级别公开结果

您可以使用TestRunner覆盖为测试类型插入发现并运行,如下所示:

在不更改测试的情况下管理全局后处理最接近的方法是:


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

谢谢,我将尝试结合起来