Class EnvironmentFixture
Used to save environment variables before unit tests run and then restore them afterwards.
Implements
Inherited Members
Namespace: Neon.Xunit
Assembly: Neon.Xunit.dll
Syntax
public class EnvironmentFixture : TestFixture, ITestFixture
Remarks
You may instantiate a single EnvironmentFixture within your unit tests to manage environment variables and test files and folders such as simulated service config and secret files.
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 : IClassFixture<EnvironmentFixture>
{
private EnvironmentFixture fixture;
public MyTests()
{
this.fixture = fixture;
if (fixture.Start() == TestFixtureStatus.AlreadyRunning)
{
fixture.Restore();
}
}
[Collection(TestCollection.NonParallel)]
[CollectionDefinition(TestCollection.NonParallel, DisableParallelization = true)]
[Fact]
public void Test()
{
}
}
Constructors
EnvironmentFixture()
Constructs the fixture.
Declaration
public EnvironmentFixture()
Methods
Dispose(bool)
Releases all associated resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Pass |
Overrides
~EnvironmentFixture()
Finalizer.
Declaration
protected ~EnvironmentFixture()
Reset()
INTERNAL USE ONLY: Resets the fixture state.
Declaration
public override void Reset()
Overrides
Restore()
Restores the original environment variables captured at the time the fixture was instantiated and also removes any temporary test files.
Declaration
public void Restore()