亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有辦法用c#讀取像[Owner="Tester"]這樣的測試屬性值

有沒有辦法用c#讀取像[Owner="Tester"]這樣的測試屬性值

C#
慕森卡 2022-12-04 13:02:42
我想知道是否有辦法讀取測試屬性值?例如[TestMethod , TestCategory ("Smoke Test"), Priority (1), Owner ("Tester")]如果有辦法使用 c# 將測試所有者屬性的值作為字符串獲取
查看完整描述

2 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

我認為TestContext可以幫助你。

var category = (string) TestContext.CurrentContext.Test.Properties.Get("Category");

我說的是運行時,否則,您可以使用(tnx to Mark Benningfield


查看完整回答
反對 回復 2022-12-04
?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

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);

        }


    }

這樣調用


var testMethod = new StackTrace().GetFrame(1)

            .GetMethod();

        var testAuthor = Helper.GetOwnerAttributeValue(testMethod, x => x.Owner);


查看完整回答
反對 回復 2022-12-04
  • 2 回答
  • 0 關注
  • 87 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號