8

I am having a unit test project and the sample code is below. Basically my plan is to create the data at run time and this data will act as a datasource for the unit tests.

[TestMethod]
[TestCategory("UITest"), TestCategory("PersonalDetailsFlow")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\TestFlows.xml", "flow", DataAccessMethod.Sequential)]
public void TestMethod1()
{
 //Test Code
} 


[ClassInitialize]
public static void ClassInit(TestContext context)
{
    DriverData driverData = new DriverData();
    driverData.DataGenerator();
}

The data creation happens in the ClassInitialize section. When I set the settings file to a testsettings file, the project runs without any issues.

When I change the testsettings file to point to a runsettings file (since I have lot of data passed from runsettings file ), I get the below error line "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"

I am quite curious to know whats happening when I run using testsettings to make it successful but when using a runsettings file, getting all issues and how to avoid this when using a runsettings file.

Also, please refer How to execute a line of code which is a data setup code in MSTest before all test

Community
  • 1
  • 1
Timothy Rajan
  • 1,947
  • 8
  • 38
  • 62

2 Answers2

8

Basically, the testsettings file is for compatibility with older unit tests. It had been replaced in VS 2013 by the runsettings. When using the testsettings, it falls back to some legacy compatibility mode which behaves differently in things like relative paths and stuff. Don't know about the actual problem you have.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
1

The difference between runsettings, and testsettings is dependent on how you want to run your unit tests.

The Microsoft explanation of both is here.

You can execute your units tests with mstest or vstest process. mstest.exe is a x86 process, and vstest.console.exe is a x64 process.

You cannot execute your unit tests with mstest.exe when you have just a runsettings alone defined.

If you wish to use mstest.exe

  • this forces you to define a testsettings with your solution.
  • you cannot run a unit test assembly that is built for a x64 target platform
  • the unit test assemblies need to be built either as x86 or AnyCpu target platform.
Sean
  • 45
  • 7