July 28, 2022

Fix 'The unit test adapter failed to connect to the data source or to read the data' in Visual Studio

  July 28, 2022

 If we are trying to data drive a test method, we may come across the below error in the visual studio.

  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.

  Stack Trace: 

TestDataSource.GetData(ITestMethod testMethodInfo, ITestContext testContext)\

This usually happens if the path of XML file does not match the file path given along with the Test Method or if the XML file is not included in the project .

Fixing this may solve this error.

If the error still exists, the XML file may not be copied to the debug folder after Build.

To confirm this, right-click on the XML file in solution explorer and Select properties.

Then change the value of 'Copy to output Directory' to 'Copy Always'



This will make sure your test data file is copied to the Output Folder, and the relative path given with the Test Method will be able to recognize it.

logoblog

Thanks for reading Fix 'The unit test adapter failed to connect to the data source or to read the data' in Visual Studio

Previous
« Prev Post

No comments:

Post a Comment

Bookmark this website for more workarounds and issue fixes.

Steps to get Tricentis Tosca Trial license activated (60 Days)

TOSCA is an automation tool that can do functional and regression testing for software products. It also includes GUI, command line interfac...