Dashboard > MbUnit > ... > MbUnit Home > NakedFixture
MbUnit Log In View a printable version of the current page.
NakedFixture
Added by Jonathan de Halleux, last edited by Jonathan de Halleux on Jul 02, 2005  (view change)
Labels: 
(None)

The NakedFixture is an attribute-free way of defining test fixtures in MbUnit.

MbUnit has a basic support for loading fixture and tests based on their names, i.e. naked fixtures . Although this may look like a step backward in functionality, this can be handy in particular situations where you want to limit dependencies. For example, if you don't want to reference any test framework, this is a good solution because it does not require any type or attribute.

Naming rules

  • class name must end with Fixture
  • fixture setup method must be named TestFixtureSetUp
  • fixture teardown method must be name TestFixtureTearDown
  • setup method must be named SetUp
  • teardown method must be named TearDown
  • test methods must end with Test
  • all rules are case sensitive

Below are two fixture. The first uses attributes and should be familiar to you. The second is it's naked equivalent:

Classic TestFixture version

Unable to find source-code formatter for language: cs. Available languages are: xhtml, javascript, java, none, html, actionscript, xml, sql
[TestFixture]
 public class ClassicFixture
 {
     [TestFixtureSetUp]
     public void TestFixtureSetUp()
     {
         Console.WriteLine("TestFixtureSetUp");
     }
     [SetUp]
     public void SetUp()
     {
         Console.WriteLine("SetUp");
     }
     [Test]
     public void FirstTest()
     {
         Console.WriteLine("Test1");
     }
     [Test]
     public void SecondTest()
     {
         Console.WriteLine("Test2");
     }
     [TearDown]
     public void TearDown()
     {
         Console.WriteLine("TearDown");
     } 
     [TestFixtureTearDown]
     public void TestFixtureTearDown()
     {
         Console.WriteLine("TestFixtureTearDown");
     }
 }

NakedFixture version:

Unable to find source-code formatter for language: cs. Available languages are: xhtml, javascript, java, none, html, actionscript, xml, sql
public class NakedFixture
 {
     public void TestFixtureSetUp()
     {
         Console.WriteLine("TestFixtureSetUp");
     }
     public void SetUp()
     {
         Console.WriteLine("SetUp");
     }
     public void FirstTest()
     {
         Console.WriteLine("Test1");
     }
     public void SecondTest()
     {
         Console.WriteLine("Test2");
     }
     public void TearDown()
     {
         Console.WriteLine("TearDown");
     }
     public void TestFixtureTearDown()
     {
         Console.WriteLine("TestFixtureTearDown");
     }
 }

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.1.4 Build:#410 Feb 15, 2006) - Bug/feature request - Contact Administrators