[英]How can I run a a method prior and after all tests are run in XUNIT, while Keeping a fixed Fixture?
I am trying to implement a BeforeAfterMethodRun Though I have already a Fixture that was not written by me and is being used in other projects.我正在尝试实现BeforeAfterMethodRun虽然我已经有一个不是我编写的 Fixture 并且正在其他项目中使用。 Is there a way how I could add this while having another base class in my class?有没有办法在我的 class 中有另一个基础 class 时添加它? I get the following error:我收到以下错误:
My goal is to Execute the command prior to any of the methods in the class is called once, which can be as well called on every method call.我的目标是在 class 中的任何方法被调用一次之前执行命令,这也可以在每个方法调用上调用。 Though these methods would not be the same and would change from class to class.虽然这些方法不会相同,并且会从 class 更改为 class。
Is there a way to achieve this?有没有办法做到这一点?
Ok So I did not understand the Attribute decoration very well.好的所以我对属性装饰不是很了解。 I could achieve this by creating a new class as:我可以通过创建一个新的 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 ");
}
}
And then Decorating the needed class as [ReportBefore]
然后将所需的 class 装饰为[ReportBefore]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.