[英]How can I run a a method prior and after all tests are run in XUNIT, while Keeping a fixed Fixture?
我正在尝试实现BeforeAfterMethodRun虽然我已经有一个不是我编写的 Fixture 并且正在其他项目中使用。 有没有办法在我的 class 中有另一个基础 class 时添加它? 我收到以下错误:
我的目标是在 class 中的任何方法被调用一次之前执行命令,这也可以在每个方法调用上调用。 虽然这些方法不会相同,并且会从 class 更改为 class。
有没有办法做到这一点?
好的所以我对属性装饰不是很了解。 我可以通过创建一个新的 class 来实现这一点:
using System;
using System.Reflection;
using Linedata.Amp.Qa.Foundation.Logger;
using Xunit.Sdk;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
class ReportBeforeAttribute : BeforeAfterTestAttribute
{
public override void Before(MethodInfo methodUnderTest)
{
Trace.Log("Starting Method");
}
public override void After(MethodInfo methodUnderTest)
{
Trace.Log("MethodFinished ");
}
}
然后将所需的 class 装饰为[ReportBefore]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.