title: "Fast" Integration Testing of WCF Services
body: <h1>Context</h1>
  <p>I am a huge fan of what Roy Osherove calls &quot;Fast Integration Testing.&quot;  This is integration testing that:</p>
  <ul>
  <li>Is performed strictly on your development box.  No need for a separate environment.</li>
  <li>Despite being integration testing, such tests are usually launched from your unit testing tool (NUnit, MsTest, etc.)</li>
  <li>Usually runs in-memory: a single process executes.</li>
  <li>Runs fast.  There should not be seconds-long deployment followed by seconds-long boot-strapping, etc.</li>
  <li>Must be source control friendly:
  <ul>
  <li>Other developers should be able simply to pull the source and run the fast integration tests, without having to battle configuration issues (e.g. setting up IIS virtual directories, etc.)</li>
  <li>Whenever possible, it should be compatible with continuous integration (CI) automated tests.</li>
  </ul>
  </li>
  </ul>
  <h1>Problem</h1>
  <p>Given a VS 2010 solution with several WCF services to be integration tested, I've been researching how best to go about this.  My further requirements of the test setup are:</p>
  <ul>
  <li>The WCF services are nested.  That is, one service might call another during the fast integration test.</li>
  <li>The WCF stack must be fully or mostly operational.
  <ul>
  <li>Calling the service contract entry point directly might be ok for unit testing, but not for this form of integration testing.</li>
  <li>REST and BasicHttp bindings should work, and preferably wsHttpBinding as well.</li>
  </ul>
  </li>
  <li>Web.config
  <ul>
  <li>The web.config transform (XDT) of each WCF project should be operational, even though a deployment may or may not occur to achieve this test.</li>
  <li>The unit test tool, such as MsTest or NUnit, should <em>not</em> require a consolidated web.config that represents all the services that will be hosted during the test.</li>
  </ul>
  </li>
  <li>The WCF service hosting can be 32 bit or 64 bit.</li>
  <li>The WCF service hosting could be either in-memory with the unit test tool, or out-of-process through such hosts as Cassini, IIS Express, etc.
  <ul>
  <li>I'm definitely leaning towards an in-memory approach, because it simplifies test-synchronization issues.  In other words, some of my WCF services execute asynchronously and are completed <em>after</em> the WCF response has already been sent to the text fixture.  With the in-memory approach I can make the test fixture <code>Monitor.Wait</code> to ensure async work is completed before the test exits.  For multi-process hosting and testing, I likely must rely on the file system and file system events to achieve the same synchronization.</li>
  </ul>
  </li>
  </ul>
  <h1>Answer?</h1>
  <p>I want to list my findings so far, and ask what tool(s) or technique(s) I'm missing.  Again, this question pertains to Visual Studio 2010, though additional comments about 2012 are welcome.</p>
  <p>For in-memory solutions, it seems there are two fundamental choices.  Either use one instance of a <a href="http://www.paraesthesia.com/archive/2008/11/26/reading-wcf-configuration-from-a-custom-location.aspx" rel="noreferrer">custom ServiceHost</a> for each service, or use one of a <a href="https://stackoverflow.com/questions/5385006/which-build-of-cassini-should-i-choose-for-production-there-are-8-public-builds">variety of other self-hosting tools</a>.  In that second link, the original question was about production hosting - but most of the listed tools are capable of self or in-memory hosting.</p>
  <p>The author of <a href="http://cassinidev.codeplex.com/" rel="noreferrer">CassiniDev</a>, mentioned in the second link above, suggested CassiniDev is used when loopback-testing (localhost) is not sufficient.  In my case, I suspect loopback-testing is fine.  That author suggests that when loop-back testing is ok, then a more lightweight story is to use his <a href="http://skysanders.net/subtext/archive/2010/04/17/a-better-visual-studio-2008-development-server-test-fixture.aspx" rel="noreferrer">WebDevServer code</a>.  If I understand correctly, the WebDevServer code is actually internal Visual Studio code that he reflected and modified for test-fixture self-hosting purposes.</p>
  <p>For on-box (multi-process) solutions, I see there is a way to make <a href="https://stackoverflow.com/questions/1890582/is-visual-studio-2010-webdev-webserver-cassini-64-bit-compatible">Cassini fit the 64 bit requirement</a>.  Otherwise, for IIS Express or IIS, I'm not sure about developer-to-developer configurability issues.  Normally when a developer configures IIS Express or IIS on a specific machine, usually other developers are left without that config info and are struggling to make the test work on their own box.  I've seen developers produce scripts that use appcmd.exe to automate such configuration, but all too often such scripts are poorly maintained.  I want to try to avoid that scenario.</p>
  <p>In either scenario, I believe my option(s) for <a href="https://stackoverflow.com/questions/3771932/tools-for-previewing-configuration-file-transformations">automating the web.config transform (XDT), without a deploy, is discussed here</a>.</p>
  <p>Ok, what are the better strategies and tactics?  I'd like to know...</p>