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.
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?
To generate unit tests, your types must be public. Open your solution in Visual Studio and then open the class file that has methods you want to test. Right-click on a method and choose Run IntelliTest to generate unit tests for the code in your method. IntelliTest runs your code many times with different inputs.
Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
To run MSTest unit tests, specify the full path to the MSTest executable (mstest.exe) in the Unit Testing Options dialog. To call this dialog directly from the editor, right-click somewhere in the editor and then click Options.
In Visual Studio 2010, the DeploymentItem
attribute is relative to the solution, but in Visual Studio 2012, it is relative to the project. Simply specify the DeploymentItem
path relative to the project folder and the unit tests will start working again.
For more info see the following link.
http://social.msdn.microsoft.com/Forums/en-US/vsunittest/thread/4a8403a2-b495-4120-aad3-0d0becc7e45e/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With