我正在尝试创建参数化测试,其中测试的参数构造如下:
问题:调用类InputDataList时,如何从测试属性访问数据?
我已经尝试在InputDataList构造函数内的TestContext中找到数据,但是没有出现在其中。 例如:
var test = TestContext.CurrentContext.Test;
//gets Test Name: "AdhocTestMethod" and zero attributes
代码:
[TestFixture]
public class MyTestSuite
{
[Test]
[MyCustomAtribuite("Data1", "Data2")]
public void Test1([InputDataList] InputData inputData)
{
// The goal is to have the inputData build with the data from
// multiple MyCustomAtribuite + File data
// e.g:
Assert.Equals(inputData.OtherStuff, "Data1");
// OR
Assert.Equals(inputData.OtherStuff, "Data2");
}
}
public class MyCustomAtribuiteAttribute : Attribute
{
public string[] myTestData { get; set; }
public MyCustomAtribuiteAttribute(params string[] mytestData)
{
this.myTestData = mytestData;
}
}
public class InputDataList : ValueSourceAttribute
{
private static List<InputData> iDataList;
public InputDataList() : base(typeof(InputDataList), "iDataList")
{
List<string> myTestData = new List<string>();
//How to get the MyCustomAtribuiteAttribute Data here?
//e.g: {"Data1", "Data2"}
//part of this data is to be loaded from a file
iDataList = new List<InputData> {
new InputData() { Browser = "Chrome", Module = "MVP_Slide", OtherStuff = myTestData[0] },
new InputData() { Browser = "IE", Module = "MVP_Slide", OtherStuff = myTestData[1] },
new InputData() { Browser = "Chrome", Module = "MVP_Slide", OtherStuff = myTestData[1] },
new InputData() { Browser = "IE", Module = "MVP_Slide", OtherStuff = myTestData[0] }
};
}
}
谢谢