title: Unit Testing the IoC container itself
body: <p>I don't think this was asked before, although it's really hard to search for a term like <em>unit test ioc container</em> and not find a question about how to implement IoC in order to perform unit tests.</p>
  
  <p>I would like to have unit tests against the IoC container itself basically because sometimes I have issues with the container (like you could with any other part of an application), and it's pretty troublesome to test the resolution of dependencies merely debugging.</p>
  
  <p>If I could introduce unit tests for these cases, I think it would save me a lot of trouble.</p>
  
  <h2>Update</h2>
  
  <p>Is something like this, not an Unit Test? Is it an integration test?</p>
  
  <pre><code>[TestClass]
  public class IoC
  {
      private IWindsorContainer _container;
  
      [TestInitialize]
      public void TestInit()
      {
          _container = new WindsorContainer();
          _container.Install(new WindsorInstaller());
      }
  
      [TestMethod]
      public void ContainerShouldResolve_MembershipProvider()
      {
          ContainerShouldResolve&lt;IMembershipProvider&gt;();
      }
  
      public void ContainerShouldResolve&lt;T&gt;()
      {
          T result = _container.Resolve&lt;T&gt;();
          Assert.IsInstanceOfType(result, typeof(T));
      }
  }
  </code></pre>
  
  <p>The only real "not self-contained" reference is a connection string I had to wire into <code>app.config</code>. Also: when trying to resolve <code>PerWebRequest</code> lifestyle components I had to add the related <code>httpModule</code>, too.</p>
  
  <p>By the way: by doing this I found out the source of my issue in little time compared to what it was taking me to debug it through using the web application.</p>