-
Notifications
You must be signed in to change notification settings - Fork 158
Apartment Attribute
CharliePoole edited this page Apr 17, 2019
·
4 revisions
The ApartmentAttribute
is used on a test method, class or assembly
to specify that the tests should be run in a particular apartment, either
the STA or the MTA.
When running tests in parallel, the test is simply scheduled to execute from a queue that uses the apartment specified. When the parallel feature is not in use, it causes creation of a new thread if the parent test is not already running in the correct apartment.
When this attribute is not specified, tests run in the MTA.
This attribute replaces the RequiresMTA and RequiresSTA attributes, which are now considered obsolete.
// All the tests in this assembly will use the MTA by default. Since
// this is the general default, the attribute is not actually needed.
[assembly:Apartment(ApartmentState.MTA)]
...
// All the tests in this assembly will use the STA by default
[assembly:Apartment(ApartmentState.STA)]
// TestFixture requiring use of the MTA. The attribute is not
// needed unless the STA was specified at a higher level.
[TestFixture, Apartment(ApartmentState.MTA)]
public class FixtureRequiringMTA
{
// All tests in the fixture will run in the MTA.
}
// TestFixture requiring use of the STA.
[TestFixture, Apartment(ApartmentState.STA)]
public class FixtureRequiringSTA
{
// All tests in the fixture will run in the STA.
}
[TestFixture]
public class AnotherFixture
{
[Test, Apartment(ApartmentState.MTA)]
public void TestRequiringMTA()
{
// This test will run in the MTA.
}
[Test, Apartment(ApartmentState.STA)]
public void TestRequiringSTA()
{
// This test will run in the STA.
}
}
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0
-
NUnit
-
Release Notes
-
License
- Getting Started
- Writing Tests
- Running Tests
- Extending NUnit
- Technical Notes
-
Release Notes
- NUnit Xamarin Runners
- VS Test Adapter
- VS Test Generator
- NUnit Analyzers