1

I am helping a team whose builds have started failing due to test failures.

The failures are being caused by missing connection string configuration. I checked the usual issues in respect of the config file to ensure that the connection string was specified with exactly the right name.

In the end I obtained the full path of the config file to check that the one on the build server contained the exact configuration that was expected.

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

The path did not point to the TestProject.exe.config file, but instead pointed to the vstest.executionengine.x86.exe.Config at the following location:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.x86.exe.Config

This file contains no connection strings at all.

When I write out all of the available connection strings from configuration, I get the default connection string:

Name: LocalSqlServer Connection: data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true . Aborting test execution.

This is coming from the machine.config file (kudos petelids).

So the big question is:

Why is the vstest.executionengine.x86.exe.Config being used rather than the app.config (at runtime TestProject.exe.config)? (I can guess that this is because the process running is the test runner, but I think it is fair to say that you would expect the test runner to let the test project use its own config file, which is what normally happens).

Fenton
  • 241,084
  • 71
  • 387
  • 401
  • Just a guess may be it is defined in the registry – Rahul Tripathi Aug 29 '14 at 11:06
  • 1
    Maybe it's coming from the machine.config file? - `%windir%\Microsoft.NET\Framework\[version]\config\machine.config` or `%windir%\Microsoft.NET\Framework64\[version]\config\machine.config` for 64-bit – petelids Aug 29 '14 at 11:21
  • @petelids - spot on. It is using that because there are no connection string in `vstest.executionengine.x86.exe.Config` - so why on earth is it using `vstest.executionengine.x86.exe.Config` rather than the app.config for the test project? – Fenton Aug 29 '14 at 12:45
  • @SteveFenton - I'm not too sure to be honest _but_ [this SO question may help](http://stackoverflow.com/questions/4811778/mstest-and-app-config-issue)? Note the EDIT/RESOLUTION in the question. – petelids Aug 29 '14 at 13:05

2 Answers2

0

I think it is fair to say that you would expect the test runner to let the test project use its own config file, which is what normally happens

That's perfectly true assumption when working with NUnit, xUnit, etc. but not with Microsoft Test Runners (MSTest and VSTest). They simply ignore target assembly config file and use their own config.

There are two solution to this problem:

  • Change MSTest to NUnit or xUnit
  • Use custom config file (not the default one)
Novakov
  • 3,055
  • 1
  • 16
  • 32
  • I was under the impression you had to explicitly pass a flag to make the tests run under the same process as MSTest, otherwise it runs them in isolation by default: `/noisolation: Run tests within the MSTest.exe process. This choice improves test run speed but increases risk to the MSTest.exe process.` http://msdn.microsoft.com/en-us/library/ms182489.aspx – Fenton Aug 29 '14 at 14:29
  • Yes but it will start new process that will use its own config file. – Novakov Aug 29 '14 at 14:36
0

MSTest runs tests in isolated mode by default.

The solution to this issue was to add a new test project and move the tests into it.

The new project behaved like all of the other projects, running the tests in an isolated process and using the app.config file from the test project.

I'm putting this down to a quirk.

Fenton
  • 241,084
  • 71
  • 387
  • 401