2
已經創建了一個從IgnoreAttribute擴展的ProdIgnoreAttribute。我已經將此屬性分配給了某些我想在DEV/QA中運行但不在PROD中執行的測試。當CurrentEnv爲Prod時,如何忽略C#中的測試
在這種情況下不會調用ApplyToTest(測試測試)方法。如何解決這個問題?
public class ProdIgnoreAttribute : IgnoreAttribute
{
private string IgnoreReason { get; }
public ProdIgnoreAttribute(string reason) : base(reason)
{
IgnoreReason = reason;
}
public new void ApplyToTest(Test test)
{
if (test.RunState == RunState.NotRunnable)
return;
if (StaticInfoHelper.VrCurrentEnv == (int)RunEnv.PROD)
{
test.RunState = RunState.Ignored;
test.Properties.Set("_SKIPREASON", (object)IgnoreReason);
}
else
{
base.ApplyToTest(test);
}
}
}
感謝您的回覆。我調整了該類以擴展和實現:NUnitAttribute,IApplyToTest,然後使用overriden方法: ApplyToTest(測試測試)並忽略了prod中的測試。如果(StaticInfoHelper.VrCurrentEnv ==(int)RunEnv.PROD) { test.RunState = RunState.Ignored; test.Properties.Set(「_ SKIPREASON」,ProdIgnoreReason); } else test.RunState = RunState.Runnable; } – ranp