2 回答

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊
我認(rèn)為TestContext可以幫助你。
var category = (string) TestContext.CurrentContext.Test.Properties.Get("Category");
我說的是運(yùn)行時(shí),否則,您可以使用它(tnx to Mark Benningfield)

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
public class Helper
{
public static TValue GetOwnerAttributeValue<TValue>(MethodBase method, Func<OwnerAttribute, TValue> valueSelector)
{
return method.GetCustomAttributes(typeof(OwnerAttribute), true).FirstOrDefault() is OwnerAttribute attr ? valueSelector(attr) : default(TValue);
}
}
這樣調(diào)用
var testMethod = new StackTrace().GetFrame(1)
.GetMethod();
var testAuthor = Helper.GetOwnerAttributeValue(testMethod, x => x.Owner);
- 2 回答
- 0 關(guān)注
- 96 瀏覽
添加回答
舉報(bào)