问题描述
我有一个非常不常见的情况.我有一个函数,让我们称之为DataGenerator.此方法生成测试执行所需的所有测试XML.这些XML在每个MSTest中均被引用为数据源.
I have a very uncommon scenario. I have a function, lets call this as DataGenerator. This method generates all test XMLs which are needed for the tests to execute. These XMLs are referenced as data source in each of the MSTests.
[TestMethod]
[TestCategory("UITest"), TestCategory("PersonalDetailsFlow")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\TestFlows.xml", "flow", DataAccessMethod.Sequential)]
public void TestMethod1()
{
//Test Code
}
然后我使用下面的代码创建测试XML
And I use the below code to create test XMLs
[ClassInitialize]
public static void ClassInit(TestContext context)
{
DriverData driverData = new DriverData();
driverData.DataGenerator();
}
运行此代码时,出现以下错误行 单元测试适配器无法连接到数据源或读取数据.有关解决此错误的详细信息,请参阅对数据驱动的单元测试进行故障排除"
When I run this code, I get the below error line The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests"
我相信这是因为MSTEST正在| DataDirectory | \ |
I believe this is because MSTEST is looking for TestFlow.xml in |DataDirectory|\|
任何人都可以帮我执行代码
Can anyone please help me how to execute the code
DriverData driverData = new DriverData();
driverData.DataGenerator();
在执行任何代码之前,我可以避免上面的消息.任何指针都很棒
before any of the code gets executed so that I can avoid the above message. Any pointers would be really great
推荐答案
您尝试使用静态构造函数吗?请参阅: MSDN-静态构造函数
did you try to use a static constructor?See: MSDN - static constructor
最好,丹尼尔
这篇关于如何在所有测试之前执行一行代码,这是MSTest中的数据设置代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!