Assembly: MbUnit.Framework (in MbUnit.Framework.dll)
Syntax
| C# | Visual Basic | Visual C++ |
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] public sealed class TestFixtureAttribute : TestFixturePatternAttribute
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := False, Inherited := True)> _ Public NotInheritable Class TestFixtureAttribute _ Inherits TestFixturePatternAttribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple = false, Inherited = true)] public ref class TestFixtureAttribute sealed : public TestFixturePatternAttribute
Members
| All Members | Constructors | Properties | Methods | Explicit Interface Implementations |
| Member | Description | |
|---|---|---|
| TestFixtureAttribute()()() |
Default constructor
| |
| TestFixtureAttribute(String) |
Constructor with a fixture description
| |
| ApartmentState | (Inherited from TestFixturePatternAttribute.) | |
| Description | (Inherited from PatternAttribute.) | |
| Equals(Object) | Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.) | |
| Finalize()()() | Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
| GetHashCode()()() | Returns the hash code for this instance. (Inherited from Attribute.) | |
| _Attribute..::.GetIDsOfNames(Guid%, IntPtr, UInt32, UInt32, IntPtr) | (Inherited from Attribute.) | |
| GetRun()()() |
Creates the execution logic
(Overrides TestFixturePatternAttribute..::.GetRun()()().) | |
| GetTimeOut()()() | (Inherited from TestFixturePatternAttribute.) | |
| GetType()()() | Gets the Type of the current instance. (Inherited from Object.) | |
| _Attribute..::.GetTypeInfo(UInt32, UInt32, IntPtr) | (Inherited from Attribute.) | |
| _Attribute..::.GetTypeInfoCount(UInt32%) | (Inherited from Attribute.) | |
| _Attribute..::.Invoke(UInt32, Guid%, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | (Inherited from Attribute.) | |
| IsDefaultAttribute()()() | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.) | |
| Match(Object) | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.) | |
| MemberwiseClone()()() | Creates a shallow copy of the current Object. (Inherited from Object.) | |
| TimeOut |
Gets or sets the fixture timeout in minutes.
(Inherited from TestFixturePatternAttribute.) | |
| ToString()()() | (Inherited from Object.) | |
| TypeId | When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.) |
Remarks
Implements: Simple Test Pattern
Login:
[SetUp]
{Test}
[TearDown]
| |
This is the classic unit test fixture attribute. It defines a class that contains unit tests.
The test execution logic is described by the following sequence of custom attributes: where [] denotes an optional attribute, {} denotes a custom attribute that can tag multiple number of methods.
Unit test methods must be tagged with the TestFixtureAttribute, return void and take no arguments:
[Test]
public void UnitTest()
{
...
}
| |
If the fixture needs initilization, you can add a set up method tagged with the SetUpAttribute attribute. Note that there can be only one method tagged with SetUpAttribute.
Symmetricaly, you can specify a method that will clean up resources allocated by the fixture. This method must be tagged with the TearDownAttribute and there can be only one method with this attribute.
Examples
This example shows a test fixture class implementing the Simple Test pattern. It tests image based method of the Graphics class in GDI+.
A set up method (tagged by SetUpAttribute is used to create a new bitmap, while a tear down (tagged by TearDownAttribute) is used to released the bitmap.
[TestFixture("Bitmap")]
public GraphicsAndBitmapTest
{
private Bitmap bmp;
[SetUp]
public void SetUp()
{
this.bmp = new Bitmap(300,300);
}
[Test]
public void CreateGraphics()
{
Graphics g = Graphcis.FromImage(this.bmp);
Assert.IsNotNull(g);
Assert.AreEqual(g.Width,this.bmp.Width);
...
}
...
[TearDown]
public void TearDownCanHaveOtherNames()
{
if(this.bmp!=null)
this.bmp.Dispose();
}
}
| |
Inheritance Hierarchy
System..::.Attribute
MbUnit.Core.Framework..::.PatternAttribute
MbUnit.Core.Framework..::.TestFixturePatternAttribute
MbUnit.Framework..::.TestFixtureAttribute