4

I have a class library-- call it Services.dll-- which is a wrapper for some third party functionality. The third party gave us a bunch of DLLs and those "inner" DLLs call a WCF service.

Normally, when Services.dll is running, it lives within the web site's process, and uses the web.config associated with the site. So when I want to define the WCF client endpoints, I edit web.config. This is very straightforward.

But now I want to write an automated integration test suite. The test project is of course a class library (let's call it Services.Tests.dll), so it will take whatever config is defined for the hosting process. But I think in the case of a test project, the hosting process is Visual Studio itself. The test project certainly does not emit an .exe of its own.

So where do I define the WCF client endpoints for the test project? Which config file do I edit? Do I edit devenv.exe.config? Do I set up some kind of "satellite" config file (e.g. Services.Tests.dll.config)-- if so, how do I get the Visual Studio test runner to pick up the config?

Or... is there a way to do this without config, by intercepting/mocking calls to System.Configuration? I can't unfortunately change the third party DLLs.

Or.. do I override with some clever use of ServicePointManager, so that config is not an issue? Not sure how I would do that.

Or... is the best practice to write an integration test project not as a class library but as an .exe, with its own app.config?

Please note-- I am not running unit tests (those are separate). These are integration tests, so I don't want to isolate away the WCF calls. I need them, and I need them to be configured to point at the right test servers.

  • Why not just configure WCF in code, without app.config at all? I did not work with WCF for several years, but when I did - I never used config files for that (in production), for various reasons. – Evk Apr 25 '17 at 10:19
  • Bear in mind that my code doesn't use WCF directly at all. We are talking about a third party library. They gave us a few DLLs and some stuff to cut and paste into web.config. – John Wu Apr 25 '17 at 11:35
3
+50

There is a simple trick you can use.

Visual Studio will load the app.config for the test project into it's host process if it's present. However, test projects don't usually have app.configs. You can force visual studio to create one by adding settings to your project:

  1. Right click your project and select "properties".
  2. Go to the "Settings" option, on the left-side bar.
  3. Insert anything on this page. Just anything will work.
  4. Save the project.

Now, you'll see that your test project has now a app.config file. Just add your WCF endpoints/bindings there and you're good.

  • Can't you just right-click project -> Add -> New Item -> Application Configuration File ? That's how I've always done it. – Eric King Apr 25 '17 at 22:35
0

My favorite solution for test projects like yours, is to maintain multiple .config file templates, using SlowCheetah to change the main config files depending on build configuration.

https://www.nuget.org/packages/SlowCheetah/

It was somewhat straighforward to keep tests in the same source code base, targetting environments like localDev, Dev, QA, Stage and Prod (with test selection too) by just changing the build configuration (which can happen automatically over continuous build environments)

That way, the test runner always get the same .config file, but the config file is changed depending on which configuration is built.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.