I have some data driven unit tests that were working just fine in Visual Studio 2010. These tests were implemented using the following pattern.
[TestMethod()]
[DeploymentItem("path_to_data_dir_relative_to_solution\\my_data.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\my_data.xml", "Token", DataAccessMethod.Sequential)]
public void MyTestMethod()
{
// Arrange
const string EXPECTED_PARAM_NAME = "table";
string data = TestContext.DataRow["Data"].ToString();
var sut = new MyClassUnderTest();
// Act
sut.DoSomething(data);
// Assert
Assert.IsTrue(sut.DidSomething);
}
Here is my solution structure.
- MySolutionFolder
- MyTestProjectFolder
- MyTestDataFolder
- my_data.xml
When I run the same tests in Visual Studio 2012, they fail with the following error message.
Result Message: 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.
Why are my unit tests suddenly failing?