[英]How can I run a a method prior and after all tests are run in XUNIT, while Keeping a fixed Fixture?
我正在嘗試實現BeforeAfterMethodRun雖然我已經有一個不是我編寫的 Fixture 並且正在其他項目中使用。 有沒有辦法在我的 class 中有另一個基礎 class 時添加它? 我收到以下錯誤:
我的目標是在 class 中的任何方法被調用一次之前執行命令,這也可以在每個方法調用上調用。 雖然這些方法不會相同,並且會從 class 更改為 class。
有沒有辦法做到這一點?
好的所以我對屬性裝飾不是很了解。 我可以通過創建一個新的 class 來實現這一點:
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 ");
}
}
然后將所需的 class 裝飾為[ReportBefore]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.