Thursday, December 04, 2008

Mocking the Unity Container

While trying to get some tests running for my current project (WPF, VS2008, C#, MSTest, RhinoMocks 3.5, Vista 64bit), I ran into an issue where I can’t mock out the Unity Container.

I was following the advice on Randy's Blog, but when I hit the line where I’m creating a stub of the IUnityContainer, the test blows up with the error below, and like others have mentioned, when in debug, the error doesn’t surface. Here’s the error I’m seeing:

Initialization method Test.Presenter.GivenPresenter.TestAnythingAndSeeItFail threw exception. System.BadImageFormatException: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B).

Seems I’m not the only one running into this error:,-but-not-when-debugging-td18742529.html


After a failed attempt to created a fake based on IUnityContainer, I ran across Roy Osherove’s post on creating an AutoMockingUnityContainer which worked perfectly for my test needs.

No comments:

Post a Comment