-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add xunit.v3 implementation #7612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Aaronontheweb
merged 5 commits into
akkadotnet:dev
from
Arkatufus:Implement-Akka.TestKit.Xunit3
May 2, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8fd1da4
Add Akka.TestKit.Xunit3 implementation
Arkatufus 8a5c8c3
Merge branch 'dev' into Implement-Akka.TestKit.Xunit3
Arkatufus eb1d596
Refactor Akka.TestKit.Xunit3 to Akka.TestKit.Xunit
Arkatufus 384a476
Merge branch 'dev' into Implement-Akka.TestKit.Xunit3
Aaronontheweb b3fddb3
Merge branch 'dev' into Implement-Akka.TestKit.Xunit3
Arkatufus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/contrib/testkits/Akka.TestKit.Xunit.Tests/Akka.TestKit.Xunit.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Import Project="../../../xunitSettings.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>$(NetFrameworkTestVersion);net8.0</TargetFrameworks> | ||
| <OutputType>Exe</OutputType> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" /> | ||
| <PackageReference Include="xunit.v3" Version="$(Xunit3Version)" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="$(Xunit3RunnerVersion)"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Akka.TestKit.Xunit\Akka.TestKit.Xunit.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
33 changes: 33 additions & 0 deletions
33
src/contrib/testkits/Akka.TestKit.Xunit.Tests/Internals/AkkaEqualExceptionSpec.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="AkkaEqualExceptionSpec.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using Akka.TestKit.Xunit.Internals; | ||
| using Xunit; | ||
|
|
||
| namespace Akka.TestKit.Xunit.Tests.Internals; | ||
|
|
||
| public static class AkkaEqualExceptionSpec | ||
| { | ||
| #if NETFRAMEWORK | ||
| [Fact] | ||
| public static void Constructor_deserializes_message() | ||
| { | ||
| var originalException = new AkkaEqualException("Test message"); | ||
|
|
||
| AkkaEqualException deserializedException; | ||
| using (var memoryStream = new System.IO.MemoryStream()) | ||
| { | ||
| var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); | ||
| formatter.Serialize(memoryStream, originalException); | ||
| memoryStream.Seek(0, System.IO.SeekOrigin.Begin); | ||
| deserializedException = (AkkaEqualException)formatter.Deserialize(memoryStream); | ||
| } | ||
|
|
||
| Assert.Equal(originalException.Message, deserializedException.Message); | ||
| } | ||
| #endif | ||
| } |
82 changes: 82 additions & 0 deletions
82
src/contrib/testkits/Akka.TestKit.Xunit.Tests/XunitAssertionsSpec.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="XunitAssertionsSpec.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using Akka.TestKit.Xunit; | ||
| using Xunit; | ||
| using Xunit.Sdk; | ||
|
|
||
| namespace Akka.TestKit.Xunit.Tests; | ||
|
|
||
| public class XunitAssertionsSpec | ||
| { | ||
| private readonly XunitAssertions _assertions = new(); | ||
|
|
||
| [Fact] | ||
| public void Assert_does_not_format_message_when_no_arguments_are_specified() | ||
| { | ||
| const string testMessage = "{Value} with different format placeholders {0}"; | ||
|
|
||
| var exception = Assert.ThrowsAny<XunitException>(() => _assertions.Fail(testMessage)); | ||
| Assert.Contains(testMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertTrue(false, testMessage)); | ||
| Assert.Contains(testMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertFalse(true, testMessage)); | ||
| Assert.Contains(testMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, testMessage)); | ||
| Assert.Contains(testMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, (_, _) => false, testMessage)); | ||
| Assert.Contains(testMessage, exception.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Assert_formats_message_when_arguments_are_specified() | ||
| { | ||
| const string testMessage = "Meaning: {0}"; | ||
| const string expectedMessage = "Meaning: 42"; | ||
|
|
||
| var exception = Assert.ThrowsAny<XunitException>(() => _assertions.Fail(testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertTrue(false, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertFalse(true, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, (_, _) => false, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Assert_catches_format_exceptions() | ||
| { | ||
| const string testMessage = "Meaning: {0} {1}"; | ||
| const string expectedMessage = "Could not string.Format"; | ||
|
|
||
| var exception = Assert.ThrowsAny<XunitException>(() => _assertions.Fail(testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertTrue(false, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertFalse(true, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
|
|
||
| exception = Assert.ThrowsAny<XunitException>(() => _assertions.AssertEqual(4, 2, (_, _) => false, testMessage, 42)); | ||
| Assert.Contains(expectedMessage, exception.Message); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/contrib/testkits/Akka.TestKit.Xunit/Attributes/LocalFactAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="LocalFactAttribute.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System; | ||
| using Xunit; | ||
| using Xunit.v3; | ||
|
|
||
| namespace Akka.TestKit.Xunit.Attributes; | ||
|
|
||
| /// <summary> | ||
| /// <para> | ||
| /// This custom XUnit Fact attribute will skip unit tests if the environment variable | ||
| /// "XUNIT_SKIP_LOCAL_FACT" exists and is set to the string "true" | ||
| /// </para> | ||
| /// <para> | ||
| /// Note that the original <see cref="Skip"/> property takes precedence over this attribute, | ||
| /// any unit tests with <see cref="LocalFactAttribute"/> with its <see cref="Skip"/> property | ||
| /// set will always be skipped, regardless of the environment variable content. | ||
| /// </para> | ||
| /// </summary> | ||
| [XunitTestCaseDiscoverer(typeof(FactDiscoverer))] | ||
| [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
| public class LocalFactAttribute: Attribute, IFactAttribute | ||
| { | ||
| private const string EnvironmentVariableName = "XUNIT_SKIP_LOCAL_FACT"; | ||
|
|
||
| private string? _skip; | ||
|
|
||
| /// <inheritdoc /> | ||
| public string? DisplayName { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool Explicit { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Type[]? SkipExceptions { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Type? SkipType { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string? SkipUnless { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string? SkipWhen { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public int Timeout { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string? Skip | ||
| { | ||
| get | ||
| { | ||
| var skipLocal = Environment.GetEnvironmentVariable(EnvironmentVariableName)? | ||
| .ToLowerInvariant(); | ||
| return skipLocal is "true" ? SkipLocal ?? "Local facts are being skipped" : _skip; | ||
| } | ||
| set => _skip = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The reason why this unit test is being skipped by the <see cref="LocalFactAttribute"/>. | ||
| /// Note that the original <see cref="FactAttribute.Skip"/> property takes precedence over this message. | ||
| /// </summary> | ||
| public string? SkipLocal { get; set; } | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/contrib/testkits/Akka.TestKit.Xunit/Attributes/LocalTheoryAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="LocalTheoryAttribute.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System; | ||
| using Xunit.v3; | ||
|
|
||
| namespace Akka.TestKit.Xunit.Attributes | ||
| { | ||
| /// <summary> | ||
| /// <para> | ||
| /// This custom XUnit Fact attribute will skip unit tests if the environment variable | ||
| /// "XUNIT_SKIP_LOCAL_THEORY" exists and is set to the string "true" | ||
| /// </para> | ||
| /// <para> | ||
| /// Note that the original <see cref="IFactAttribute.Skip"/> property takes precedence over this attribute, | ||
| /// any unit tests with <see cref="LocalTheoryAttribute"/> with its <see cref="IFactAttribute.Skip"/> property | ||
| /// set will always be skipped, regardless of the environment variable content. | ||
| /// </para> | ||
| /// </summary> | ||
| [XunitTestCaseDiscoverer(typeof(TheoryDiscoverer))] | ||
| [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] | ||
| public class LocalTheoryAttribute : LocalFactAttribute, ITheoryAttribute | ||
| { | ||
| /// <inheritdoc /> | ||
| public bool DisableDiscoveryEnumeration { get; set; } | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool SkipTestWithoutData { get; set; } | ||
| } | ||
| } |
71 changes: 71 additions & 0 deletions
71
src/contrib/testkits/Akka.TestKit.Xunit/Attributes/WindowsFactAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="WindowsFactAttribute.cs" company="Akka.NET Project"> | ||
| // Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
| // Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System; | ||
| using Xunit.v3; | ||
|
|
||
| namespace Akka.TestKit.Xunit.Attributes | ||
| { | ||
| /// <summary> | ||
| /// <para> | ||
| /// This custom XUnit Fact attribute will skip unit tests if the run-time environment is not windows | ||
| /// </para> | ||
| /// <para> | ||
| /// Note that the original <see cref="Skip"/> property takes precedence over this attribute, | ||
| /// any unit tests with <see cref="WindowsFactAttribute"/> with its <see cref="Skip"/> property | ||
| /// set will always be skipped, regardless of the environment variable content. | ||
| /// </para> | ||
| /// </summary> | ||
| public class WindowsFactAttribute : Attribute, IFactAttribute | ||
| { | ||
| private string? _skip; | ||
|
|
||
|
|
||
| /// <inheritdoc /> | ||
| public string? DisplayName { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool Explicit { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Type[]? SkipExceptions { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public Type? SkipType { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string? SkipUnless { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string? SkipWhen { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public int Timeout { get; set; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string? Skip | ||
| { | ||
| get | ||
| { | ||
| if (_skip != null) | ||
| return _skip; | ||
|
|
||
| var platform = Environment.OSVersion.Platform; | ||
| var notWindows = platform is PlatformID.MacOSX or PlatformID.Unix or PlatformID.Xbox; | ||
| return notWindows ? SkipUnix ?? "Skipped under Unix platforms" : null; | ||
| } | ||
| set => _skip = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The reason why this unit test is being skipped by the <see cref="WindowsFactAttribute"/>. | ||
| /// Note that the original <see cref="Skip"/> property takes precedence over this message. | ||
| /// </summary> | ||
| public string? SkipUnix { get; set; } | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's going to be a bit of a breaking change but you know, at some point we have to step into the future here.