简体   繁体   中英

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. Is there a way how I could add this while having another base class in my 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. Though these methods would not be the same and would change from class to 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:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM