Creating Self-testing Assemblies

Test assemblies can be turned into executables which run all their tests on their own and generate an HTML report with very little effort. This comes in handy if you don’t have a test runner to hand and it won’t hinder testing if you do. You simply pass the .exe file to the GUI or console runner instead of the .dll you were passing previously.

  1. Add an empty code file to your test project.
  2. Use the autorunner code snippet to add the following code to the file. Change the code namespace as required.

    Copy 
    using MbUnit.Core;
    
    namespace MbUnit.Tests
    {
       static class Program
       {
          public static void Main(string[] args)
          {
             using (AutoRunner auto = new AutoRunner())
             {
                auto.Run();
                auto.ReportToHtml();
             }
          }
       }
    }
  3. Open the test project’s properties dialog. In the Application tab, change the Output Type to “Console Application” and Startup object to the class you just created in step 2.

    Visual Studio Project Properties dialog set to create an executable self-test runner.

  4. Build your solution and press F5 to test.