C# 是否将IWrapTestMethod属性应用于整个装置?

C# 是否将IWrapTestMethod属性应用于整个装置?,c#,nunit,nunit-3.0,C#,Nunit,Nunit 3.0,我有一个NUnitIWrapTestMethod属性: public class OutputElapsedTimeAttribute : Attribute, IWrapTestMethod { public TestCommand Wrap(TestCommand command) { return new OutputElapsedTimeCommand(command); } } 以及相应的BeforeAndAfterTest命令: public

我有一个NUnit
IWrapTestMethod
属性:

public class OutputElapsedTimeAttribute : Attribute, IWrapTestMethod
{
    public TestCommand Wrap(TestCommand command)
    {
        return new OutputElapsedTimeCommand(command);
    }
}
以及相应的BeforeAndAfterTest命令:

public class OutputElapsedTimeCommand : BeforeAndAfterTestCommand
{
    private Stopwatch _sw;

    public OutputElapsedTimeCommand(TestCommand innerCommand) : base(innerCommand)
    {
        BeforeTest = ctx => { _sw = Stopwatch.StartNew(); };
        AfterTest = ctx =>
        {
            _sw.Stop();
            ctx.OutWriter.WriteLineAsync($"Took: {_sw.ElapsedMilliseconds}ms");
        };
    }
}

当我将该属性应用于测试方法时,将正确调用并执行该命令。我希望能够将该属性放在测试夹具上,并将其自动应用于测试夹具中的所有测试。怎么做?我在文档中找不到任何合适的接口。

NUnit仅在具有该接口属性的测试中调用该接口。NUnit也可以调用包含每个测试的fixture上的属性,但它没有这样做,因此需要对NUnit本身进行增强


作为一个解决方案,考虑创建一个

,你看到了这篇文章,在那里他们声明了“代码>头脑”,我们只允许在方法上使用属性,因为我相信命令包装不支持装饰测试夹具。< /代码>嗯……有没有不同的方法来实现我正在尝试的东西?我现在不知道。谢谢。“最终”答案。我将在GitHub提交一个功能请求:-)