Skip to content

Commit

Permalink
Update Akka.TestKit.NUnit to NUnit v4 (3rd attempt) (akkadotnet#136)
Browse files Browse the repository at this point in the history
* Update to NUnit 4

This commit is based on the work of Sean Killeen
in PR akkadotnet#112.
Additional changes:
* add net462 as target framework
* set C# version in test projects to C# 10 so that file scoped namespaces work

* Use constraint assertion model even in NUnit 3 adapter

- This improves consistency between NUnit 3 and 4 adapters

* Convert "AssertEqual-with-comparer" to NUnit constraint model

Our adapters are no longer using custom assertions. This will result in
failure reports that are consistent with other NUnit reports, especially
when the report output changes (like it did between NUnit 3 and 4).

* Apply ".editorconfig" configuration to "Directory.Build.props"

This commit only changes indentation whitespace, making this MSBuild
file consistent with other MSBuild files in the repository (.csproj).

* Add missing/recommended NuGet package properties

* Replace obsolete "PackageIconUrl" with "PackageIcon"

Fixes warning NU5048 during "dotnet pack".
https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5048

* Replace obsolete "PackageLicenseUrl" with "PackageLicenseExpression"

* Simplify ".csproj" files + move common references to "Directory.Build.props"

* Dynamically fill in current copyright year

* Consolidate release notes + bump version to 1.6.0-preview.1

* Move "PackageReference" back to ".csproj" files

* Fix NuGet package name in "RELEASE_NOTES.md"

- Thanks FarrisPandell

* NuGet update 2024-09-06

Akka.TestKit 1.5.28, Microsoft.NET.Test.Sdk 17.11.1

* Delete empty lines after version headers in "RELEASE_NOTES.md"

- Empty lines are confusing Nuke build

---------

Co-authored-by: Urs Metz <urs.metz@gmx.de>
  • Loading branch information
milang and UrsMetz authored Sep 6, 2024
1 parent 9e1fd17 commit 42348b1
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 99 deletions.
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Auto detect text files and perform LF normalization
* text=auto


# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
Expand Down Expand Up @@ -29,3 +28,6 @@
*.txt text eol=crlf

build.sh eol=lf

# Binary files (no newline adjustment)
*.png binary
21 changes: 14 additions & 7 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
## [1.6.0] / September 2024
- Bump `Akka.TestKit` to [1.5.28](https://github.com/akkadotnet/akka.net/releases/tag/1.5.28)
- Bump `NUnit3TestAdapter` to [4.6.0](https://github.com/nunit/nunit3-vs-adapter/releases/tag/V4.6.0)
- Add `NUnit.Analyzers` version [4.3.0](https://github.com/nunit/nunit.analyzers/releases/tag/4.3.0) to ensure we follow NUnit best practices.
- Add support for [NUnit 4.2.2](https://github.com/nunit/nunit/releases/tag/4.2.2) in addition to NUnit 3.
`Akka.TestKit.NUnit` targets NUnit 4, while `Akka.TestKit.NUnit3` targets NUnit 3.

## [1.5.24] / June 11 2024
- [Bump Akka.TestKit to 1.5.24](https://github.com/akkadotnet/akka.net/releases/tag/1.5.24)
- [Bump NUnit3TestAdapter to 4.5.0](https://github.com/akkadotnet/Akka.TestKit.NUnit/pull/97)
- [Bump NUnit to 3.14.0](https://github.com/akkadotnet/Akka.TestKit.NUnit/pull/116)
- Bump Akka.TestKit to [1.5.24](https://github.com/akkadotnet/akka.net/releases/tag/1.5.24) ([#124](https://github.com/akkadotnet/Akka.TestKit.NUnit/pull/124))
- Bump NUnit3TestAdapter to [4.5.0](https://github.com/nunit/nunit3-vs-adapter/releases/tag/V4.5.0) ([#97](https://github.com/akkadotnet/Akka.TestKit.NUnit/pull/97))
- Bump NUnit to [3.14.0](https://github.com/nunit/nunit/releases/tag/v3.14.0) ([#116](https://github.com/akkadotnet/Akka.TestKit.NUnit/pull/116))

## [1.4.39] / July 22 2022
- Support for Akka 1.4.39
- Support for NUnit 3.13.3
- Now targets `netstandard2.0`
- All `TestKit` classes now implement `[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]` which guarantees a unique `ActorSystem` instance per-run. All previous TestKit hacks needed to support this are now removed. See https://github.com/akkadotnet/Akka.TestKit.NUnit/issues/44 for details.
- Support for Akka 1.4.39
- Support for NUnit 3.13.3
- Now targets `netstandard2.0`
- All `TestKit` classes now implement `[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]` which guarantees a unique `ActorSystem` instance per-run. All previous TestKit hacks needed to support this are now removed. See [#44](https://github.com/akkadotnet/Akka.TestKit.NUnit/issues/44) for details.
21 changes: 6 additions & 15 deletions src/Akka.TestKit.NUnit.Tests/Akka.TestKit.NUnit.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>Akka.TestKit.NUnit.Tests</AssemblyTitle>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Akka.TestKit.NUnit\Akka.TestKit.NUnit.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnitAdapterVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" PrivateAssets="all" />
<PackageReference Include="NUnit.Analyzers" Version="$(NUnitAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnitTestAdapterVersion)" PrivateAssets="all" />
<ProjectReference Include="../Akka.TestKit.NUnit/Akka.TestKit.NUnit.csproj" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
</Project>
</Project>
13 changes: 5 additions & 8 deletions src/Akka.TestKit.NUnit/Akka.TestKit.NUnit.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Akka.TestKit.NUnit</AssemblyTitle>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<!-- Matches frameworks targeted by NUnit 4.x.x. -->
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.TestKit" Version="$(AkkaTestKitVersion)" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="NUnit.Analyzers" Version="$(NUnitAnalyzersVersion)" PrivateAssets="all" /><!-- ensure we follow NUnit best practices; "PrivateAssets" is needed to not include analyzers as dependencies in ".nupkg" -->
<PackageReference Include="NUnit" Version="$(NUnit4Version)" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
</Project>
18 changes: 6 additions & 12 deletions src/Akka.TestKit.NUnit/NUnitAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,27 @@ public class NUnitAssertions : ITestKitAssertions

public void Fail(string format = "", params object[] args)
{
Assert.Fail(format, args);
Assert.Fail(string.Format(format, args));
}

public void AssertTrue(bool condition, string format = "", params object[] args)
{
Assert.IsTrue(condition, format, args);
Assert.That(condition, Is.True, string.Format(format, args));
}

public void AssertFalse(bool condition, string format = "", params object[] args)
{
Assert.IsFalse(condition, format, args);
Assert.That(condition, Is.False, string.Format(format, args));
}

public void AssertEqual<T>(T expected, T actual, string format = "", params object[] args)
{
Assert.AreEqual(expected, actual, format, args);
Assert.That(actual, Is.EqualTo(expected), string.Format(format, args));
}

public void AssertEqual<T>(T expected, T actual, Func<T, T, bool> comparer, string format = "", params object[] args)
{
if (!comparer(expected, actual))
throw new AssertionException($"Assert.AreEqual failed. Expected [{FormatValue(expected)}]. Actual [{FormatValue(actual)}]. {string.Format(format, args)}");
}

private static string FormatValue<T>(T expected)
{
return ReferenceEquals(expected, null) ? "null" : expected.ToString();
Assert.That(actual, Is.EqualTo(expected).Using<T>(comparer), string.Format(format, args));
}
}
}
}
21 changes: 6 additions & 15 deletions src/Akka.TestKit.NUnit3.Tests/Akka.TestKit.NUnit3.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>Akka.TestKit.NUnit3.Tests</AssemblyTitle>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Akka.TestKit.NUnit3\Akka.TestKit.NUnit3.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnitAdapterVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" PrivateAssets="all" />
<PackageReference Include="NUnit.Analyzers" Version="$(NUnitAnalyzersVersion)" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="$(NUnitTestAdapterVersion)" PrivateAssets="all" />
<ProjectReference Include="../Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.csproj" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
</Project>
</Project>
14 changes: 6 additions & 8 deletions src/Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyTitle>Akka.TestKit.NUnit</AssemblyTitle>
<!--
NUnit 3.x.x targets "net35;net40;net45;netstandard2.0", but we have to exclude
frameworks not supported by "Akka.TestKit". -->
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.TestKit" Version="$(AkkaTestKitVersion)" />
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<PackageReference Include="NUnit.Analyzers" Version="$(NUnitAnalyzersVersion)" PrivateAssets="all" /><!-- ensure we follow NUnit best practices; "PrivateAssets" is needed to not include analyzers as dependencies in ".nupkg" -->
<PackageReference Include="NUnit" Version="$(NUnit3Version)" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
</Project>
18 changes: 7 additions & 11 deletions src/Akka.TestKit.NUnit3/NUnitAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System;
using NUnit.Framework;

#pragma warning disable NUnit2050 // NUnit 4 no longer supports string.Format specification

namespace Akka.TestKit.NUnit3
{
/// <summary>
Expand All @@ -23,28 +25,22 @@ public void Fail(string format = "", params object[] args)

public void AssertTrue(bool condition, string format = "", params object[] args)
{
Assert.IsTrue(condition, format, args);
Assert.That(condition, Is.True, format, args);
}

public void AssertFalse(bool condition, string format = "", params object[] args)
{
Assert.IsFalse(condition, format, args);
Assert.That(condition, Is.False, format, args);
}

public void AssertEqual<T>(T expected, T actual, string format = "", params object[] args)
{
Assert.AreEqual(expected, actual, format, args);
Assert.That(actual, Is.EqualTo(expected), format, args);
}

public void AssertEqual<T>(T expected, T actual, Func<T, T, bool> comparer, string format = "", params object[] args)
{
if (!comparer(expected, actual))
throw new AssertionException($"Assert.AreEqual failed. Expected [{FormatValue(expected)}]. Actual [{FormatValue(actual)}]. {string.Format(format, args)}");
}

private static string FormatValue<T>(T expected)
{
return ReferenceEquals(expected, null) ? "null" : expected.ToString();
Assert.That(actual, Is.EqualTo(expected).Using<T>(comparer), format, args);
}
}
}
}
64 changes: 42 additions & 22 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
<Project>
<PropertyGroup>
<Copyright>Copyright © 2013-2022</Copyright>
<Authors>Akka.NET Contrib</Authors>
<Description>TestKit for writing tests for Akka.NET using NUnit.</Description>
<VersionPrefix>1.5.0</VersionPrefix>
<PackageReleaseNotes> • Support for Akka 1.4.39
• Support for NUnit 3.13.3
• Now targets netstandard2.0
• All TestKit classes now implement [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] which guarantees a unique ActorSystem instance per-run. All previous TestKit hacks needed to support this are now removed. See https://github.com/akkadotnet/Akka.TestKit.NUnit/issues/44 for details.</PackageReleaseNotes>
<PackageTags>akka;actors;actor model;Akka;concurrency;testkit;nunit</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageIconUrl>http://getakka.net/images/akkalogo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/AkkaNetContrib/Akka.TestKit.Nunit</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/AkkaNetContrib/Akka.TestKit.Nunit</PackageLicenseUrl>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup>
<NUnitVersion>3.14.0</NUnitVersion>
<NUnitAdapterVersion>4.5.0</NUnitAdapterVersion>
<AkkaTestKitVersion>1.5.26</AkkaTestKitVersion>
</PropertyGroup>
</Project>
<PropertyGroup>
<Copyright>Copyright © 2013-$([System.DateTime]::Now.Year)</Copyright>
<Authors>Akka.NET Contrib</Authors>
<Description>TestKit for writing tests for Akka.NET using NUnit.</Description>
<VersionPrefix>1.6.0</VersionPrefix>
<VersionSuffix>preview.1</VersionSuffix>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../../RELEASE_NOTES.md").Substring(0,567))</PackageReleaseNotes>
<PackageTags>akka;actors;actor model;Akka;concurrency;testkit;nunit</PackageTags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageIcon>akka.png</PackageIcon><!-- https://github.com/NuGet/Home/wiki/Packaging-Icon-within-the-nupkg -->
<PackageProjectUrl>https://github.com/AkkaNetContrib/Akka.TestKit.Nunit</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile><!-- https://devblogs.microsoft.com/nuget/add-a-readme-to-your-nuget-package/ -->
<NoWarn>$(NoWarn);CS1591</NoWarn>
<LangVersion>10.0</LangVersion>
<ContinuousIntegrationBuild Condition=" '$(Configuration)' == 'Release' ">true</ContinuousIntegrationBuild><!-- https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#continuousintegrationbuild -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder><!-- https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/nuget#symbol-packages -->
<EmbedUntrackedSources>true</EmbedUntrackedSources><!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
<PublishRepositoryUrl>true</PublishRepositoryUrl><!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#publishrepositoryurl -->
</PropertyGroup>
<PropertyGroup>
<AkkaTestKitVersion>1.5.28</AkkaTestKitVersion>
<MicrosoftNetTestSdkVersion>17.11.1</MicrosoftNetTestSdkVersion>
<NUnit3Version>3.14.0</NUnit3Version>
<NUnit4Version>4.2.2</NUnit4Version>
<NUnitAnalyzersVersion>4.3.0</NUnitAnalyzersVersion>
<NUnitTestAdapterVersion>4.6.0</NUnitTestAdapterVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" $(IsPackable) ">
<!-- Referenced by "PackageReadmeFile" property. -->
<None Include="../../README.md" Pack="true" Visible="false" PackagePath="" />
<!--
Based on the following (official) NuGet example:
https://github.com/NuGet/Samples/blob/master/PackageIconExample/PackageIconExample.csproj
(note that image path is relative to .csproj file, not this .props file) -->
<None Include="../akka.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
</Project>
Binary file added src/akka.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 42348b1

Please sign in to comment.