C# 将nunit自定义动作属性与设置方法一起使用
我已经阅读了,我想创建一个可以在测试方法或设置方法上使用的操作属性(以避免在所有测试方法上重复该属性) 我创建了以下类(与文档中的类非常相似,但我尝试允许所有内容): 什么有效:C# 将nunit自定义动作属性与设置方法一起使用,c#,nunit,custom-attributes,C#,Nunit,Custom Attributes,我已经阅读了,我想创建一个可以在测试方法或设置方法上使用的操作属性(以避免在所有测试方法上重复该属性) 我创建了以下类(与文档中的类非常相似,但我尝试允许所有内容): 什么有效: [Test, CustomAction("TEST")] public void BasicAssert() { } [SetUp, CustomAction("SETUP")] public void CustomAttributeBeforeSetup()
[Test, CustomAction("TEST")]
public void BasicAssert()
{
}
[SetUp, CustomAction("SETUP")]
public void CustomAttributeBeforeSetup()
{
System.Diagnostics.Debug.WriteLine("Inside Setup");
}
[Test]
public void BasicAssert()
{
}
在nunit测试运行程序文本输出窗格中,我有
*****Test.CustomerT.BasicAssert内部设置
案例前:测试,来自CustomerT.BasicAssert.
案例后:测试,来自CustomerT.BasicAssert 什么不起作用:
[Test, CustomAction("TEST")]
public void BasicAssert()
{
}
[SetUp, CustomAction("SETUP")]
public void CustomAttributeBeforeSetup()
{
System.Diagnostics.Debug.WriteLine("Inside Setup");
}
[Test]
public void BasicAssert()
{
}
在nunit测试运行程序文本输出窗格中,我有
*****Test.CustomerT.BasicAssert内部设置 ?
如何创建可以在Setup方法上执行的自定义属性?我假设您真正想要的是在整个测试装置之前和之后运行BeforeTest和AfterTest。如果是这种情况,那么将属性放在Fixture上,即test类,而不是放在SetUp方法上。在TestDetails中,您可以通过检查TestDetails.IsSuite来查看是否为测试或夹具运行了特定的方法(即测试前和测试后)