Class TestFixture
Abstract test fixture base class.
Inheritance
Implements
Namespace: Neon.Xunit
Assembly: Neon.Xunit.dll
Syntax
public abstract class TestFixture : ITestFixture
Remarks
note
IMPORTANT: The base Neon TestFixture implementation DOES NOT
support parallel test execution. You need to explicitly disable parallel execution in
all test assemblies that rely on thesex test fixtures by adding a C# file called
AssemblyInfo.cs
with:
[assembly: CollectionBehavior(DisableTestParallelization = true, MaxParallelThreads = 1)]
and then define your test classes like:
public class MyTests
{
[Collection(TestCollection.NonParallel)]
[CollectionDefinition(TestCollection.NonParallel, DisableParallelization = true)]
[Fact]
public void Test()
{
}
}
Test fixtures that modify global machine or other environmental state must
implement a public static void EnsureReset()
method resets the state
to reasonable defaults. These will be reflected and called when the first
TestFixture is created by the test runner for every test class.
Constructors
TestFixture()
Constructs the fixture.
Declaration
public TestFixture()
Properties
InAction
Returns true
if the Start(Action) method
is running.
Declaration
protected bool InAction { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsDisposed
Returns true
if the instance has been disposed.
Declaration
protected bool IsDisposed { get; set; }
Property Value
Type | Description |
---|---|
bool |
IsRunning
Returns true
if the fixture has been initialized.
Declaration
public bool IsRunning { get; set; }
Property Value
Type | Description |
---|---|
bool |
State
Used by unit test classes to persist arbitrary name/value information across individual unit tests.
Declaration
public IDictionary<string, object> State { get; }
Property Value
Type | Description |
---|---|
IDictionary<string, object> |
Methods
CheckDisposed()
Verifies that the fixture instance has not been disposed.
Declaration
protected void CheckDisposed()
CheckWithinAction()
Verifies that the fixture instance's Start(Action) method is executing.
Declaration
protected void CheckWithinAction()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Releases all associated resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Pass |
~TestFixture()
Finalizer.
Declaration
protected ~TestFixture()
OnRestart()
Called when an already started fixture is being restarted. This provides the fixture an opportunity to do some custom initialization. This base method does nothing.
note
This method is intended only for use by test fixture implementations. Unit tests or test fixtures should never call this directly.
Declaration
public virtual void OnRestart()
Reset()
INTERNAL USE ONLY: Resets the fixture state.
Declaration
public virtual void Reset()
Start(Action)
Starts the fixture if it hasn't already been started including invoking the optional Action when the first time Start(Action) is called for a fixture instance.
Declaration
public virtual TestFixtureStatus Start(Action action = null)
Parameters
Type | Name | Description |
---|---|---|
Action | action | The optional custom start action. |
Returns
Type | Description |
---|---|
TestFixtureStatus | Started if the fixture wasn't previously started and this method call started it or AlreadyRunning if the fixture was already running. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this is called from within the Action. |