This page last changed on Jun 02, 2006 by peli.

MbUnit defines the AssemblyCleanUpAttribute that can be used to define guard methods that will act at the assembly level. Typically, highly time consuming resources can be initialized and cleaned up using those methods.

Rationale

  • The user provides a class containing static methods tagged with SetUpAttribute and TearDownAttribute (both are optional).
  • A assembly-level attribute, AssemblyCleanUpAttribute, is used to specify which class contains the method.
  • If the setup method fails, no tests are executed.
  • If the teardown method fails, all tests are failed

Example

This example outputs the starting and finishing time of the tests.

Unable to find source-code formatter for language: cs. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
// in AssemblyInfo.csĀ 
[assembly: MbUnit.Framework.AssemblyCleanup(typeof(MbUnit.Demo.AssemblyCleaner))]

// in AssemblyCleaner.cs
using System;
using MbUnit.Framework;

namespace MbUnit.Demo
{
    public static class AssemblyCleaner
    {
        [SetUp]
        public static void SetUp()
        {
            Console.WriteLine("Setting up {0}", typeof(AssemblyCleaner).Assembly.FullName);
            Console.WriteLine(DateTime.Now.ToLongTimeString());
        }
        [TearDown]
        public static void TearDown()
        {
            Console.WriteLine("Cleaning up {0}", typeof(AssemblyCleaner).Assembly.FullName);
            Console.WriteLine(DateTime.Now.ToLongTimeString());
        }
    }
}
Document generated by Confluence on Jun 11, 2007 11:56