Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the difference between runsettings and testsettings in MSTest

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

like image 921
Timothy Rajan Avatar asked Jun 10 '16 07:06

Timothy Rajan


People also ask

What is Runsettings?

runsettings file is to customize code coverage analysis. Run settings files can be used to configure tests that are run from the command line, from the IDE, or in a build workflow using Azure Test Plans or Team Foundation Server (TFS). Run settings files are optional.

How do I add code coverage to Runsettings?

You can enable this in runsettings by adding <Format>Cobertura</Format> or <Format>Xml</Format> in the DataCollector configuration section in your runsettings file. This format can be viewed in the code coverage results window in Visual Studio Enterprise.

Does MSTest run tests in parallel?

The biggest advantage of MSTest is that it allows parallelization at the method level. As opposed to the other frameworks which only allow parallelization at the class level. So, for example, If you have 100 test methods in 5 classes, MSTest will let you run 100 tests in parallel.


1 Answers

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.

like image 143
Stefan Steinegger Avatar answered Nov 15 '22 21:11

Stefan Steinegger