How to unittest the UnityBootstrapper ?

Topics: Prism v4 - WPF 4
Jan 24, 2014 at 10:04 AM
Edited Jan 24, 2014 at 10:07 AM
Since my boostrapper, derived from UnityBootstrapper does lots of "things" I would like to unit test it.

First unit-test "instantiation"
var bootStrapper = new AppBootstrapper();

nest unitTest "Run":
here I run into my first problem (see below)

Are there any "best practices" available on how to unittest a Unitybootstraper?

Thanks for Help and Hints

public void RunCanBeCalled()
// Arrange
var bootStrapper = new AppBootstrapper();

// Act

// Assert

Test method X1.PrintDataPreparation.Testing.UnitTests.GuiMain.The_AppBootstrapper.RunCanBeCalled threw exception:
System.IO.FileLoadException: Die Datei oder Assembly "Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)
bei Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.Run(Boolean runWithDefaultConfiguration)
bei Microsoft.Practices.Prism.Bootstrapper.Run()
bei X1.PrintDataPreparation.Testing.UnitTests.GuiMain.The_AppBootstrapper.RunCanBeCalled() in The_AppBootstrapper.cs: line 60.
Jan 24, 2014 at 2:02 PM

Based on my understanding, the Run() method would not be tested as that would be an integration test with UI interaction, trying to show the App.xaml view which is causing the exception.

Therefore, in order to unit test each BootStrapper method you could use Mock objects and configure only the parameters you would need.

For more information and help on the tests implementation you could look into the Prism Library BootstrapperFixture Test Class.

I hope this helps, regards.

Gabriel Ostrowsky
Marked as answer by RainerQ on 1/27/2014 at 12:40 AM
Jan 27, 2014 at 7:40 AM
Hello Gabriel,

thank you very much for your hints. I think they will help me to proceed to unit test my BootStrapper.