Skip to content

Commit 3bcc5eb

Browse files
feat: Remove AwesomeAssertions, use TUnit built-in assertions (#49)
TUnit ships its own async fluent assertion API so AwesomeAssertions is an unnecessary dependency that can be dropped. ## What changed - Removed `AwesomeAssertions` from `Directory.Packages.props` and `TrxLib.Tests.csproj`. - Migrated all three test files to TUnit's native assertions: - `x.Should().Be(y)` -> `await Assert.That(x).IsEqualTo(y)` - `x.Should().Contain(y)` -> `await Assert.That(x).Contains(y)` - `x.Should().HaveCount(n)` -> `await Assert.That(x).HasCount(n)` - `x.Should().ContainSingle(pred)` -> `await Assert.That(x).HasSingleItem(pred)` - `x.Should().NotBeNull()` / `.BeNull()` -> `await Assert.That(x).IsNotNull()` / `.IsNull()` - `act.Should().NotThrow<T>()` -> direct invocation (TUnit surfaces exceptions automatically) - `AssertionScope` blocks -> sequential `await Assert.That(...)` calls - All `void` test methods that now use `await` were updated to `async Task`. All 65 tests pass after the migration.
1 parent 0af743d commit 3bcc5eb

5 files changed

Lines changed: 157 additions & 172 deletions

File tree

Directory.Packages.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
This would typically list all NuGet packages used within this solution.
1818
-->
1919
<ItemGroup>
20-
<PackageVersion Include="AwesomeAssertions" Version="9.4.0" />
2120
<PackageVersion Include="IntelliTect.Multitool" Version="2.0.0" />
2221
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.203" />
2322
<PackageVersion Include="Moq" Version="4.20.70" />

TrxLib.Tests/TestResultTests.cs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using AwesomeAssertions;
2-
using AwesomeAssertions.Execution;
1+
using TUnit.Assertions;
32

43
namespace TrxLib.Tests;
54

@@ -9,77 +8,76 @@ public class TestResultTests
98
[Arguments("namespace.class.test", "namespace")]
109
[Arguments("deeper.namespace.class.test", "deeper.namespace")]
1110
[Arguments("still.deeper.namespace.class.test", "still.deeper.namespace")]
12-
public void Namespace_is_parsed_correctly(
11+
public async Task Namespace_is_parsed_correctly(
1312
string fullyQualifiedTestName,
1413
string expectedNamespace)
1514
{
1615
var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted);
17-
testResult.Namespace.Should().Be(expectedNamespace);
16+
await Assert.That(testResult.Namespace).IsEqualTo(expectedNamespace);
1817
}
1918

2019
[Test]
2120
[Arguments("namespace.class.test")]
2221
[Arguments("deeper.namespace.class.test")]
2322
[Arguments("still.deeper.namespace.class.test")]
24-
public void TestName_is_parsed_correctly(
23+
public async Task TestName_is_parsed_correctly(
2524
string fullyQualifiedTestName)
2625
{
2726
var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted);
28-
testResult.TestName.Should().Be("test");
27+
await Assert.That(testResult.TestName).IsEqualTo("test");
2928
}
3029

3130
[Test]
3231
[Arguments("namespace.class.test")]
3332
[Arguments("deeper.namespace.class.test")]
3433
[Arguments("still.deeper.namespace.class.test")]
35-
public void ClassName_is_parsed_correctly(
34+
public async Task ClassName_is_parsed_correctly(
3635
string fullyQualifiedTestName)
3736
{
3837
var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted);
39-
testResult.ClassName.Should().Be("class");
38+
await Assert.That(testResult.ClassName).IsEqualTo("class");
4039
}
4140

4241
[Test]
4342
[Arguments("namespace.class.test", "namespace.class")]
4443
[Arguments("deeper.namespace.class.test", "deeper.namespace.class")]
4544
[Arguments("still.deeper.namespace.class.test", "still.deeper.namespace.class")]
4645
[Arguments("deeper.namespace.class.theorytest(command: \"build\")", "deeper.namespace.class")]
47-
public void FullyQualifiedClassName_is_parsed_correctly(
46+
public async Task FullyQualifiedClassName_is_parsed_correctly(
4847
string fullyQualifiedTestName,
4948
string expected)
5049
{
5150
var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted);
52-
testResult.FullyQualifiedClassName.Should().Be(expected);
51+
await Assert.That(testResult.FullyQualifiedClassName).IsEqualTo(expected);
5352
}
5453

5554
[Test]
56-
public void Theory_test_is_parsed_correctly()
55+
public async Task Theory_test_is_parsed_correctly()
5756
{
5857
var testResult = new TestResult(
5958
"Microsoft.DotNet.Cli.MSBuild.IntegrationTests.GivenDotnetInvokesMSBuild.When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(command: \"build\")",
6059
outcome: TestOutcome.Passed);
6160

62-
using var _ = new AssertionScope();
63-
testResult.TestName.Should().Be("When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(command: \"build\")");
64-
testResult.Namespace.Should().Be("Microsoft.DotNet.Cli.MSBuild.IntegrationTests");
65-
testResult.ClassName.Should().Be("GivenDotnetInvokesMSBuild");
61+
await Assert.That(testResult.TestName).IsEqualTo("When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(command: \"build\")");
62+
await Assert.That(testResult.Namespace).IsEqualTo("Microsoft.DotNet.Cli.MSBuild.IntegrationTests");
63+
await Assert.That(testResult.ClassName).IsEqualTo("GivenDotnetInvokesMSBuild");
6664
}
6765

6866
[Test]
6967
[Arguments("Cell 1: #r \"nuget:TRexLib\"")]
7068
[Arguments("Cell 1: Console.Write(\"Hello world.\";")]
71-
public void Inferred_properties_are_not_inferred_from_fully_qualified_test_name_if_they_do_not_match_dotnet_standards(
69+
public async Task Inferred_properties_are_not_inferred_from_fully_qualified_test_name_if_they_do_not_match_dotnet_standards(
7270
string fullyQualifiedTestName)
7371
{
7472
var testResult = new TestResult(fullyQualifiedTestName, TestOutcome.NotExecuted);
75-
testResult.ClassName.Should().BeNull();
76-
testResult.FullyQualifiedClassName.Should().BeNull();
77-
testResult.Namespace.Should().BeNull();
78-
testResult.TestName.Should().Be(fullyQualifiedTestName);
73+
await Assert.That(testResult.ClassName).IsNull();
74+
await Assert.That(testResult.FullyQualifiedClassName).IsNull();
75+
await Assert.That(testResult.Namespace).IsNull();
76+
await Assert.That(testResult.TestName).IsEqualTo(fullyQualifiedTestName);
7977
}
8078

8179
[Test]
82-
public void Theory_test_with_dotted_param_is_parsed_correctly_when_testMethod_provided()
80+
public async Task Theory_test_with_dotted_param_is_parsed_correctly_when_testMethod_provided()
8381
{
8482
// When testMethod is supplied the constructor must use testMethod.ClassName
8583
// directly instead of splitting the FQTN on '.'. Without the fix, a param
@@ -91,22 +89,20 @@ public void Theory_test_with_dotted_param_is_parsed_correctly_when_testMethod_pr
9189
var testResult = new TestResult(fqtn, TestOutcome.Passed,
9290
testMethod: new TestMethod { ClassName = className, Name = methodName });
9391

94-
using var _ = new AssertionScope();
95-
testResult.FullyQualifiedTestName.Should().Be(fqtn);
96-
testResult.FullyQualifiedClassName.Should().Be(className);
97-
testResult.ClassName.Should().Be("ParserTests");
98-
testResult.Namespace.Should().Be("System.CommandLine.Tests");
99-
testResult.TestName.Should().Be($"{methodName}(param: \"foo.bar\")");
92+
await Assert.That(testResult.FullyQualifiedTestName).IsEqualTo(fqtn);
93+
await Assert.That(testResult.FullyQualifiedClassName).IsEqualTo(className);
94+
await Assert.That(testResult.ClassName).IsEqualTo("ParserTests");
95+
await Assert.That(testResult.Namespace).IsEqualTo("System.CommandLine.Tests");
96+
await Assert.That(testResult.TestName).IsEqualTo($"{methodName}(param: \"foo.bar\")");
10097
}
10198

10299
[Test]
103-
public void ToString_DoesNotThrow_ForOutcomeValueNotInEnum()
100+
public async Task ToString_DoesNotThrow_ForOutcomeValueNotInEnum()
104101
{
105102
// TestResult.ToString() has a _ => throw arm that crashes on any enum value
106103
// not listed in its switch expression (e.g. future additions to TestOutcome, or
107104
// values written by vstest that TrxLib doesn't yet map, such as "Completed").
108105
var testResult = new TestResult("some.namespace.SomeClass.SomeTest", (TestOutcome)99);
109-
var act = () => testResult.ToString();
110-
act.Should().NotThrow<ArgumentOutOfRangeException>();
106+
await Assert.That(() => testResult.ToString()).ThrowsNothing();
111107
}
112-
}
108+
}

TrxLib.Tests/TrxLib.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="AwesomeAssertions" />
1413
<PackageReference Include="IntelliTect.Multitool" />
1514
<PackageReference Include="TUnit" />
1615
</ItemGroup>

TrxLib.Tests/TrxParserRegressionTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.IO;
22

3-
using AwesomeAssertions;
3+
using TUnit.Assertions;
44

55
namespace TrxLib.Tests;
66

@@ -17,11 +17,11 @@ public class TrxParserRegressionTests
1717
[Arguments("Aborted", TestOutcome.Aborted)]
1818
[Arguments("NotRunnable", TestOutcome.NotRunnable)]
1919
[Arguments(null, TestOutcome.Error)] // absent attribute = Error
20-
public void Parse_OutcomeAttribute_RoundTrips(string? outcomeAttr, TestOutcome expected)
20+
public async Task Parse_OutcomeAttribute_RoundTrips(string? outcomeAttr, TestOutcome expected)
2121
{
2222
using var trxFile = new TempTrxFile(MinimalTrx(outcome: outcomeAttr));
2323
var results = TrxParser.Parse(trxFile.FileInfo);
24-
results.Single().Outcome.Should().Be(expected);
24+
await Assert.That(results.Single().Outcome).IsEqualTo(expected);
2525
}
2626

2727
// TestProjectDirectory must resolve to the project root for all standard .NET SDK
@@ -34,14 +34,14 @@ public void Parse_OutcomeAttribute_RoundTrips(string? outcomeAttr, TestOutcome e
3434
];
3535

3636
[Test, MethodDataSource(nameof(DirectoryLayouts))]
37-
public void Parse_TestProjectDirectory_ResolvesFromBinAnchor(string subfolder, string[] segments)
37+
public async Task Parse_TestProjectDirectory_ResolvesFromBinAnchor(string subfolder, string[] segments)
3838
{
3939
var projectRoot = Path.GetFullPath(Path.Combine(Path.GetTempPath(), subfolder));
4040
var codebase = Path.Combine(new[] { projectRoot }.Concat(segments).ToArray());
4141
using var trxFile = new TempTrxFile(MinimalTrx(codeBase: codebase));
4242
var results = TrxParser.Parse(trxFile.FileInfo);
43-
results.Single().TestProjectDirectory!.FullName.TrimEnd(Path.DirectorySeparatorChar)
44-
.Should().Be(projectRoot.TrimEnd(Path.DirectorySeparatorChar));
43+
await Assert.That(results.Single().TestProjectDirectory!.FullName.TrimEnd(Path.DirectorySeparatorChar))
44+
.IsEqualTo(projectRoot.TrimEnd(Path.DirectorySeparatorChar));
4545
}
4646

4747
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)