Skip to content

Commit

Permalink
Merge pull request #6 from skbkontur/fix-global-teardown
Browse files Browse the repository at this point in the history
Fix Global TearDown
  • Loading branch information
fakefeik authored Jul 13, 2021
2 parents 714b865 + b8de7e5 commit d8798c0
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.0.50 - 2021.07.13
- Fix Global TearDown behaviour (GroboTestSuite teardowns now work only in .NET Core).
- Update dependencies.

## v1.0.44 - 2021.03.14
- Update dependencies.
- Run tests against net5.0 tfm.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.IO;
using System.Reflection;

using FluentAssertions;

using GroboContainer.NUnitExtensions.Impl.TestContext;

using NUnit.Framework;

namespace GroboContainer.NUnitExtensions.Tests.ExecutionOrder
{
public static class Log
{
public static void Clear()
{
if (File.Exists(filename))
File.Delete(filename);
}

public static void Line(string line)
{
File.AppendAllLines(filename, new[] {line});
}

public static void Check(string[] expectedLines)
{
File.ReadAllLines(filename).Should().BeEquivalentTo(expectedLines);
}

private static readonly string filename = TestContext.CurrentContext.TestDirectory + "/GlobalTearDown.log";
}

public class AndLocalTearDown : GroboTestMethodWrapperAttribute
{
public override void SetUp(string testName, IEditableGroboTestContext suiteContext, IEditableGroboTestContext methodContext)
{
Log.Line("AndLocalTearDown.SetUp");
}

public override void TearDown(string testName, IEditableGroboTestContext suiteContext, IEditableGroboTestContext methodContext)
{
Log.Line("AndLocalTearDown.TearDown");
}
}

[AndLocalTearDown]
public class WithGlobalTearDown : GroboTestSuiteWrapperAttribute
{
public override void SetUp(string suiteName, Assembly testAssembly, IEditableGroboTestContext suiteContext)
{
Log.Clear();
Log.Line("WithGlobalTearDown.SetUp");
}

public override void TearDown(string suiteName, Assembly testAssembly, IEditableGroboTestContext suiteContext)
{
Log.Line("WithGlobalTearDown.TearDown");
}
}

[GroboTestSuite("GlobalTearDown"), WithGlobalTearDown]
public class GlobalTearDownTest
{
[Test]
public void Test()
{
Log.Line("GlobalTearDownTest.Test");
}
}

[Explicit]
public class AfterTestCheck
{
[Test]
public void Test()
{
Log.Check(new[]
{
"WithGlobalTearDown.SetUp",
"AndLocalTearDown.SetUp",
"GlobalTearDownTest.Test",
"AndLocalTearDown.TearDown",
"WithGlobalTearDown.TearDown",
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="JetBrains.Annotations" Version="2020.3.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="GroboContainer" Version="1.2.60" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit" Version="3.13.2" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion GroboContainer.NUnitExtensions/Impl/GroboTestAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ private static void EnsureAppDomainInitialization()
{
if (!appDomainIsInitialized)
{
AppDomain.CurrentDomain.DomainUnload += (sender, args) => OnAppDomainUnload();
if (AppDomain.CurrentDomain.IsDefaultAppDomain())
AppDomain.CurrentDomain.ProcessExit += (sender, args) => OnAppDomainUnload();
else
AppDomain.CurrentDomain.DomainUnload += (sender, args) => OnAppDomainUnload();
appDomainIsInitialized = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build_script:

test_script:
- cmd: dotnet test --no-build --configuration Release ./GroboContainer.NUnitExtensions.Tests/GroboContainer.NUnitExtensions.Tests.csproj
- cmd: dotnet test --no-build --configuration Release --framework net5.0 ./GroboContainer.NUnitExtensions.Tests/GroboContainer.NUnitExtensions.Tests.csproj --filter FullyQualifiedName=GroboContainer.NUnitExtensions.Tests.ExecutionOrder.AfterTestCheck.Test

artifacts:
- path: './GroboContainer.NUnitExtensions/bin/Release/*.nupkg'
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "5.0.103"
"version": "5.0.301"
}
}

0 comments on commit d8798c0

Please sign in to comment.