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
I didn’t gey any reply from last 17 hours. As it was important for me, so I tried to explore other possibilities.
Finally I made it to work. Below is the simple solution (I am posting this because it might help other begineers like me, in future).
I have just moved my XML file generation code to
[ClassInitialize]method instead ofTestInitialize()and it worked fine.Also, below is the order that methods will be run is:
Check Here for more
Thanks…