0

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
    } 

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"

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

Timothy Rajan
  • 1,947
  • 8
  • 38
  • 62

1 Answers1

0

did you try to use a static constructor? See: MSDN - static constructor

Best, Daniel

Daniel W.
  • 938
  • 8
  • 21
  • Yes. But getting the same result. – Timothy Rajan Jun 10 '16 at 06:34
  • I believe I need to live with it. – Timothy Rajan Jun 10 '16 at 06:35
  • You can convert the XML generation in an exe and create a PowerShell script to run that program first and then the tests. You can also put the results of the generation in the TestContext and remove the DataSource attrubute. But look first at a XML that already exists: see [this](http://stackoverflow.com/questions/16025719/why-does-data-driven-unit-test-fail-in-vs2012-when-it-worked-fine-in-vs2010) SO question; maybe you have the same problem. – Jeroen Heier Jun 10 '16 at 12:54