Should I be unit testing my bootstrapper and if so how? Should I be unit testing my bootstrapper and if so how? wpf wpf

Should I be unit testing my bootstrapper and if so how?


Yeah, I would just modify your Bootstrapper slightly to help with the testing:

public class Bootstrapper : UnityBootstrapper{    protected override DependencyObject CreateShell()    {        return Container.Resolve<MainWindow>();    }    protected override void InitializeShell()    {        base.InitializeShell();        Window app_window = Shell as Window;        if((app_window != null) && (Application.Current != null))        {           Application.Current.MainWindow = app_window;           Application.Current.MainWindow.Show();        }    }    protected override void ConfigureModuleCatalog()    {        ModuleCatalog moduleCatalog = (ModuleCatalog)ModuleCatalog;        moduleCatalog.AddModule(typeof(MainShellModule));    }}

Then you could have your unit test look something like this:

[TestFixture, RequiresSTA]public class BootstrapperTest{   // Declare private variables here   Bootstrapper b;   /// <summary>   /// This gets called once at the start of the 'TestFixture' attributed   /// class. You can create objects needed for the test here   /// </summary>   [TestFixtureSetUp]   public void FixtureSetup()   {      b = new Bootstrapper();      b.Run();   }   /// <summary>   /// Assert container is created   /// </summary>   [Test]   public void ShellInitialization()   {      Assert.That(b.Container, Is.Not.Null);   }   /// <summary>   /// Assert module catalog created types   /// </summary>   [Test]   public void ShellModuleCatalog()   {      IModuleCatalog mod = ServiceLocator.Current.TryResolve<IModuleCatalog>();      Assert.That(mod, Is.Not.Null);      // Check that all of your modules have been created (based on mod.Modules)   }}