Why does the data driven by unit test crash in vs2012 when it worked perfectly in vs2010?

I have some unit tests based on data that worked fine in Visual Studio 2010. These tests were implemented using the following template.

[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 could not connect to the data source or read the data. For more information about resolving this error, see the "Troubleshooting Test Data Problems" section ( http://go.microsoft.com/fwlink/?LinkId=62412 ) in the MSDN library. Error Details: The object reference was not installed in the object instance.

Why do my unit tests fail unexpectedly?

+5
c # visual-studio-2010 visual-studio-2012 deploymentitem data-driven-tests
source share
1 answer

In Visual Studio 2010, the DeploymentItem attribute refers to the solution , but in Visual Studio 2012 it refers to the project . Just specify the DeploymentItem path relative to the project folder, and the unit tests will start working again.

See the following link for more information.

http://social.msdn.microsoft.com/Forums/en-US/vsunittest/thread/4a8403a2-b495-4120-aad3-0d0becc7e45e/

+8
source share

All Articles