如何使用xUnit框架中的ExcelData属性来运行我在Excel中的测试用例。早些时候,当我看到相关的帖子时,它起作用了。但是现在它没有标识为属性。
发布于 2017-08-30 23:02:37
早些时候,它曾经是xUnit库的一部分,现在不是了。您需要包含此处的文件
发布于 2018-06-26 16:41:11
我最终在Visual Studio2017中创建了一个XUnit项目,然后从TheoryData类继承了我自己的数据类。
[Theory(DisplayName = "Example_Test")]
[ClassData(typeof(MyDataSource))]
public void SpreadsheetDriven(testnumber, firstString, secondString)
{
Assert.AreEqual(firstString, secondString);
}
public class MyDataSource: TheoryData<int, string, string>
{
public MyDataSource()
{
Add(1, "Red", "Red");
Add(2, "Red", "Blue");
}
}我使用EPPlus库将电子表格读取到此数据源中,并在测试中使用它们。最后,一切都做得很好(特别是当我意识到EPPlus在读取单元格/行/列时使用基于1的集合时;)
这是EPPlus:https://github.com/VahidN/EPPlus.Core,这是让我走上强类型数据源集合之路的教程:https://andrewlock.net/creating-strongly-typed-xunit-theory-test-data-with-theorydata/
https://stackoverflow.com/questions/45962056
复制相似问题