I don't think this was asked before, although it's really hard to search for a term like unit test ioc container and not find a question about how to implement IoC in order to perform unit tests.
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.
If I could introduce unit tests for these cases, I think it would save me a lot of trouble.
Update
Is something like this, not an Unit Test? Is it an integration test?
[TestClass]
public class IoC
{
private IWindsorContainer _container;
[TestInitialize]
public void TestInit()
{
_container = new WindsorContainer();
_container.Install(new WindsorInstaller());
}
[TestMethod]
public void ContainerShouldResolve_MembershipProvider()
{
ContainerShouldResolve<IMembershipProvider>();
}
public void ContainerShouldResolve<T>()
{
T result = _container.Resolve<T>();
Assert.IsInstanceOfType(result, typeof(T));
}
}
The only real "not self-contained" reference is a connection string I had to wire into app.config
. Also: when trying to resolve PerWebRequest
lifestyle components I had to add the related httpModule
, too.
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.
No comments:
Post a Comment