Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AssemblyInitializeAttribute Class

 

Identifies a method that contains code to be used before all tests in the assembly have run and to allocate resources obtained by the assembly. This class cannot be inherited.

Namespace:   Microsoft.VisualStudio.TestTools.UnitTesting
Assembly:  Microsoft.VisualStudio.QualityTools.UnitTestFramework (in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)

System::Object
  System::Attribute
    Microsoft.VisualStudio.TestTools.UnitTesting::AssemblyInitializeAttribute

[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple = false)]
public ref class AssemblyInitializeAttribute sealed : Attribute

NameDescription
System_CAPS_pubmethodAssemblyInitializeAttribute()

Initializes a new instance of the AssemblyInitializeAttribute class.

NameDescription
System_CAPS_pubpropertyTypeId

(Inherited from Attribute.)

NameDescription
System_CAPS_pubmethodEquals(Object^)

(Inherited from Attribute.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Attribute.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodIsDefaultAttribute()

(Inherited from Attribute.)

System_CAPS_pubmethodMatch(Object^)

(Inherited from Attribute.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

The method marked with this attribute will be run before methods marked with the ClassInitializeAttribute, TestInitializeAttribute, and TestMethodAttribute attributes. Only one method in an assembly may be decorated with this attribute.

System_CAPS_importantImportant

This attribute should not be used on ASP.NET unit tests, that is, any test with [HostType("ASP.NET")] attribute. Because of the stateless nature of IIS and ASP.NET, a method decorated with this attribute might be called more than once per test run.

This attribute can be specified on a method. Only one instance of this attribute may be applied to a method.

System_CAPS_noteNote

The test engine runs a method that is marked with the AssemblyInitialize attribute only if that method is a member of a class that is marked with the TestClass attribute.

For more information about how to use attributes, see Extending Metadata Using Attributes.

Legacy Code Example

The following examples demonstrate the initialization and clean-up attributes that are used to indicate which methods should be run by the test engine at different periods of the test.

The first code samples contain a class and method to test. To run this example, create a class library project and replace the code with the following example.

No code example is currently available or this language may not be supported.

The following example contains code to test DivideMethod() found in the previous code examples. Create a test project and put the following code in a test class document. Add the appropriate references to the project. This code contains attributes that control the initialization and clean-up execution order for the method, class, and assembly.

In particular, note the AssemblyInitialize attribute on the AssemblyInit()method.

No code example is currently available or this language may not be supported.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: