I am trying to use an dynamically generated XML file with Data Driven test. I am using Visual Studio 2010 and .NET 4.0 .
[TestMethod]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", @"|DataDirectory|\StudentData.xml", "Student", DataAccessMethod.Sequential)]
This StudentData.xml
file is being generated by code and I am not deploying this file. I have written the code for generating StudentData.xml
file in TestInitialize()
method, also the file is being saved at current working directory.
Whenever I am going to run the test method it is throwing error:
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" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.
Error details: Object reference not set to an instance of an object.
What I think is before creating the file, the framework is trying to access the file. So, How can I use this XML file with unit test? Also, can I use variable names in Attributes?
Thanks for your help