C# 当它';是否设置了TestFixture级别而不是测试级别?

C# 当它';是否设置了TestFixture级别而不是测试级别?,c#,unit-testing,testing,nunit,C#,Unit Testing,Testing,Nunit,我想为testFixture设置一个作者,并在运行时获取它,以便能够在我的数据库中获取它: 下面是TestFixture类 我为testFixture级别设置了Nunit属性Author: [TestFixture(Author = nameof(AuthorName.Eva)),MachineCategory.Filter] public class FilterTests : WidiaTestSetup { [Test, RetryOnFailureOrExcepti

我想为testFixture设置一个作者,并在运行时获取它,以便能够在我的数据库中获取它:

下面是
TestFixture
类 我为testFixture级别设置了Nunit属性Author:

[TestFixture(Author = nameof(AuthorName.Eva)),MachineCategory.Filter]
public class FilterTests : WidiaTestSetup
{  

        [Test, RetryOnFailureOrException]
        public void FilterCuttingDiameter()
        { ...}
} 
要从测试级别I获取测试作者,请执行以下操作:

Author = TestContext.CurrentContext.Test.Properties.Get("Author").ToString()
但是它在testFixture中不起作用 如何从
TestFixture
级别获取它


提前感谢

虽然这不是一个非常优雅的解决方案,但反射可能是您在这里的最佳选择

var author=GetType().CustomAttributes.First().NamedArguments.First(x=>x.MemberName.Equals(“author”).TypedValue.ToString();

我建议在一次性设置中执行此操作,以避免每次测试产生任何不必要的成本。

可在夹具的
TestContext
中找到。只需将其保存在
OneTimeSetUp
方法中的某个位置

[OneTimeSetUp]
公共权限(作者)
{
_fixtureAuthor=TestContext.CurrentContext.Test.Properties.Get(“Author”).ToString();
}