There is a concept known as 'Setup' and 'Teardown' when unit testing.
You can define methods in your test class which have special significance to the test framework (ie. MS Test, NUnit) which is executing your tests. You can use following attributes with MS Test class, which specify code to be run
each test is run [TestInitialize]
a test has finished running TestCleanup]
- before any
tests are run [ClassInitialize]
- after all tests have been executed [ClassCleanup]
I don't use CastleWindsor myself, but your code would look something along following lines ...
public class MyTestClass
private static IWindsorContainer _Container;
public static void ClassInit(TestContext context)
var container = new WindsorContainer();
_Container = container;
public void MyTestMethod()
IObjectToTest obj = _Container.Resolve<IObjectToTest>();
var result = obj.MyMethod();
public static void ClassCleanup()
Hope that helps get you started!