Tuesday, 21 October 2014

TeamCity NUnit + App.Config

WCF is hard enough without the NUnit tests in TeamCity throwing up:

SetUp method failed. SetUp : System.InvalidOperationException : Could not find endpoint element with name 'selfHostingClientEndpointFormat' and contract 'TestModelServerServiceReference.IModelServerService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.

I wouldn't mind so much but the tests work fine within Visual Studio and using NUnit console/GUI.

It turns out that the JetBrains.BuildServer.NUnitLauncher.exe uses a different strategy to find the application config files to NUnit.

Throw a test Assembly at NUnit and it uses the assembly's config file (*.dll.config) BUT the JetBrains NUnitLauncher assumes an App.Config in the same folder instead ... why???

I ended up adding the following PowerShell Build Step to copy the existing config files to app.config:

Get-ChildItem -Recurse -Include *.test.dll.config $PSScriptRoot |? { $_ -ilike "*\bin\*" } |% {
  $appConfig = Join-Path $_.DirectoryName "App.config"
  Write-Host "$($_.Name): Copying to App.config"
  Copy-Item $_ $appConfig