Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test projects not reading app.config in TeamCity -> NUnit phase

Tags:

teamcity

nunit

Well we are facing a strange problem with JetBrains TeamCity induced unit tests on our main project where tests from few library projects are failing regularly. Apparently, it's not reading the config file (coming from app.config and nicely stored in project -> bin -> debug -> projectName.dll.config).

Hints or tips on what could be the real issue would be highly appreciated.

like image 438
user446923 Avatar asked Apr 20 '11 05:04

user446923


3 Answers

I've got the same problem and wasted a couple of hours to figure out what the problem is.

In our case, the NUnit plugin was configured to run the tests from:

**\*Tests.dll

Though this sounds to be OK, it has turned out that this pattern will not only match to the MyTests.dll in the bin\Debug folder but also to the obj\Debug\MyTests.dll. The obj folder is used internally for the compilation and does not contain the config file.

Finally the solution was to change the plugin configuration to

**\bin\Debug\*Tests.dll

Actually we use a system variable for the build configuration so we did not have the "Debug" hard-coded. Using bin* might be also dangerous when the workspace is also used for Debug/Release builds and you don't have a full cleanup specified.

You might wonder why I did not realize the test count mismatch (actually it was doubled, because they were running once from bin and once from obj), but this is typical: while everything is green, you don't care about the count. When we have introduced the first test depending on the config, we had only one failure (because the one from bin was passing), so the duplication was not outstanding.

like image 92
Gaspar Nagy Avatar answered Nov 01 '22 21:11

Gaspar Nagy


In addition to Gaspar Nagy's accepted answer, check to see if your project has multiple test dlls and one of them is referencing another.

This causes the referenced dll to be run twice, and the copy that was in the other dll's folder to not have the proper app.config entries. The proper fix is to remove any and all references from the other test project.

like image 45
DMac the Destroyer Avatar answered Nov 01 '22 20:11

DMac the Destroyer


TeamCity (v6.5.4) has its own NUnit Test Runner and there seems to be an inconsistency between it and the NUnit GUI test runner (2.5.10). The NUnit GUI Test Runner follows the long standing convention of expecting the configuration file name to be of the format .config. You can see this in NUnit by looking at Project -> Edit...

TeamCity on the other hand is looking for an app.config.

Your options are to either:

  1. Set the NUnit GUI to point to app.config and include the resultant nunit project in your source control.
  2. Have both an app.config and a .config - syncing both manualy.
  3. Add a step to your build process to copy .config to app.config (or vice versa).
like image 6
Martin Clarke Avatar answered Nov 01 '22 21:11

Martin Clarke