Skip to content

Commit d767a2a

Browse files
authored
🧪 Migrate to Awesome Assertions (#497)
1 parent 2b93978 commit d767a2a

File tree

8 files changed

+90
-9
lines changed

8 files changed

+90
-9
lines changed

.github/workflows/publish-log4brains.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install and Build Log4brains
2424
run: |
2525
npm install -g log4brains
26-
log4brains build
26+
log4brains build --basePath /${GITHUB_REPOSITORY#*/}
2727
2828
- name: Deploy
2929
uses: JamesIves/[email protected]

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.1.0" />
1313
<PackageVersion Include="Aspire.Hosting.SqlServer" Version="9.1.0" />
1414
<PackageVersion Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="9.1.0" />
15+
<PackageVersion Include="AwesomeAssertions" Version="8.0.2"/>
1516
<PackageVersion Include="Azure.Identity" Version="1.13.0" />
1617
<PackageVersion Include="Bogus" Version="35.6.1" />
1718
<PackageVersion Include="coverlet.collector" Version="6.0.2">
@@ -20,7 +21,6 @@
2021
</PackageVersion>
2122
<PackageVersion Include="EntityFrameworkCore.Exceptions.SqlServer" Version="8.1.3" />
2223
<PackageVersion Include="ErrorOr" Version="2.0.1" />
23-
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
2424
<PackageVersion Include="FluentValidation.DependencyInjectionExtensions" Version="11.11.0" />
2525
<PackageVersion Include="JunitXml.TestLogger" Version="4.1.0" />
2626
<PackageVersion Include="MediatR" Version="12.4.1" />
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Migrate to Awesome Assertions
2+
3+
- Status: accepted
4+
- Deciders: Daniel Mackay, Luke Cooke, Anton Polkanov, Matt Parker
5+
- Date: 2025-03-26
6+
- Tags: testing, unit-tests, assertions, awesome-assertions, fluent-assertions
7+
8+
Technical Story: https://github.com/SSWConsulting/SSW.CleanArchitecture/pull/497
9+
10+
## Context and Problem Statement
11+
12+
We have been using FluentAssertions for our unit tests.
13+
14+
This library is great however, the project has now switched to a paid model. Versions 8 and beyond are free for open-source projects and non-commercial use, but commercial use requires a paid licence.
15+
16+
Version 7 will remain fully open-source indefinitely and receive bugfixes and other important corrections.
17+
18+
## Decision Drivers
19+
20+
- Free for commercial use
21+
- Concise and readable assertions
22+
23+
## Considered Options
24+
25+
1. Shouldly
26+
2. Fluent Assertions (free version)
27+
3. Fluent Assertions (paid version)
28+
4. Native test framework assertions (e.g. xUnit/NUnit/TUnit)
29+
5. Awesome Assertions
30+
31+
## Decision Outcome
32+
33+
Chosen option: "Option 5 - Awesome Assertions", because we get the same experience as FluentAssertions, but it is free for commercial use. It is also easy to migrate from FluentAssertions to Awesome Assertions.
34+
35+
## Pros and Cons of the Options <!-- optional -->
36+
37+
### Option 1 - Shouldly
38+
39+
https://docs.shouldly.org/
40+
41+
- ✅ Good assertion library
42+
- ✅ Free for commercial use
43+
- ❌ Would require a lot of work to migrate from FluentAssertions
44+
- ❌ Custom extensions would need to be rewritten
45+
46+
### Option 2 - Fluent Assertions (free version)
47+
48+
https://xceed.com/products/unit-testing/fluent-assertions/
49+
50+
- ✅ Great assertion library
51+
- ✅ Version 7 is Free for open-source projects and non-commercial use
52+
- ❌ Easy to upgrade to version 8, resulting in substantial licence fees
53+
54+
### Option 3 - Fluent Assertions (paid version)
55+
56+
https://xceed.com/products/unit-testing/fluent-assertions/
57+
58+
- ✅ Great assertion library
59+
- ❌ Substantial licence fees for commercial use. ($130 per developer per year. For SSW this would cost $7,410 per year for 57 developers)
60+
61+
### Option 4 - Native test framework assertions (e.g. xUnit/NUnit/TUnit)
62+
63+
- ✅ Free for commercial use
64+
- ✅ No additional dependencies
65+
- ❌ Assertions are not as readable as FluentAssertions
66+
- ❌ Would require a lot of work to migrate from FluentAssertions
67+
- ❌ Custom extensions would need to be rewritten
68+
69+
### Option 5 - Awesome Assertions
70+
71+
https://awesomeassertions.org/
72+
73+
- ✅ Great assertion library
74+
- ✅ Free for commercial use
75+
- ✅ Easy to migrate from FluentAssertions
76+
- ✅ Custom extensions will continue to work (with minor modifications)

tests/Architecture.Tests/Architecture.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="AwesomeAssertions"/>
910
<PackageReference Include="coverlet.collector">
1011
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1112
<PrivateAssets>all</PrivateAssets>
1213
</PackageReference>
13-
<PackageReference Include="FluentAssertions" />
1414
<PackageReference Include="JunitXml.TestLogger" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1616
<PackageReference Include="NetArchTest.Rules" />

tests/Architecture.Tests/Common/TestResultAssertions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ namespace SSW.CleanArchitecture.Architecture.UnitTests.Common;
66

77
public class TestResultAssertions : ReferenceTypeAssertions<TestResult, TestResultAssertions>
88
{
9-
public TestResultAssertions(TestResult instance) : base(instance)
9+
private readonly AssertionChain _chain;
10+
11+
public TestResultAssertions(TestResult instance, AssertionChain chain) : base(instance, chain)
1012
{
13+
_chain = chain;
1114
}
1215

1316
protected override string Identifier => "TestResult";
1417

18+
[CustomAssertion]
1519
public AndConstraint<TestResultAssertions> BeSuccessful(string because = "", params object[] becauseArgs)
1620
{
17-
Execute.Assertion
21+
_chain
1822
.BecauseOf(because, becauseArgs)
1923
.Given(() => Subject)
2024
.ForCondition(s => s.IsSuccessful)

tests/Architecture.Tests/Common/TestResultExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Xunit.Abstractions;
1+
using FluentAssertions.Execution;
2+
using Xunit.Abstractions;
23

34
namespace SSW.CleanArchitecture.Architecture.UnitTests.Common;
45

@@ -15,5 +16,5 @@ public static void DumpFailingTypes(this TestResult result, ITestOutputHelper ou
1516
outputHelper.WriteLine(type.FullName);
1617
}
1718

18-
public static TestResultAssertions Should(this TestResult result) => new(result);
19+
public static TestResultAssertions Should(this TestResult result) => new(result, AssertionChain.GetOrCreate());
1920
}

tests/Domain.UnitTests/Domain.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="AwesomeAssertions"/>
910
<PackageReference Include="coverlet.collector">
1011
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1112
<PrivateAssets>all</PrivateAssets>
1213
</PackageReference>
13-
<PackageReference Include="FluentAssertions" />
1414
<PackageReference Include="JunitXml.TestLogger" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" />
1616
<PackageReference Include="xunit" />

tests/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="AwesomeAssertions"/>
910
<PackageReference Include="Bogus" />
1011
<PackageReference Include="coverlet.collector">
1112
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1213
<PrivateAssets>all</PrivateAssets>
1314
</PackageReference>
14-
<PackageReference Include="FluentAssertions" />
1515
<PackageReference Include="JunitXml.TestLogger" />
1616
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
1717
<PackageReference Include="Microsoft.NET.Test.Sdk" />

0 commit comments

Comments
 (0)