Skip to content

Commit c5628c4

Browse files
committed
docs: update README for xUnit v3 (async data pipeline, usage examples, upgrade guidance)
1 parent ef8b1a9 commit c5628c4

File tree

1 file changed

+79
-9
lines changed

1 file changed

+79
-9
lines changed

README.md

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
1-
[![NuGet Version](https://img.shields.io/nuget/v/Atc.Test.svg?logo=nuget&style=for-the-badge)](https://www.nuget.org/packages/atc.test)
2-
31
# ATC Test
42

5-
Common tools for writing tests using XUnit, AutoFixture, NSubstitute and FluentAssertions.
3+
![NuGet Version](https://img.shields.io/nuget/v/Atc.Test.svg?logo=nuget&style=for-the-badge)
4+
5+
Common tools for writing tests using xUnit, AutoFixture, NSubstitute and FluentAssertions.
6+
7+
## Package References
8+
9+
Add `Atc.Test` to the project containing your tests or to a shared test utilities project.
10+
11+
Typical test project (excerpt):
12+
13+
```xml
14+
<Project Sdk="Microsoft.NET.Sdk">
15+
<PropertyGroup>
16+
<TargetFramework>net9.0</TargetFramework>
17+
<OutputType>Exe</OutputType>
18+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
19+
</PropertyGroup>
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
22+
<PackageReference Include="xunit.v3" Version="3.0.1" />
23+
<PackageReference Include="Atc.Test" Version="$(LatestOrPinned)" />
24+
</ItemGroup>
25+
<!-- Remove legacy AutoFixture.Xunit2 using if brought transitively -->
26+
<ItemGroup>
27+
<Using Remove="AutoFixture.Xunit2" />
28+
</ItemGroup>
29+
</Project>
30+
```
631

7-
> **Version Notes:**
8-
> If you are using the `MemberAutoNSubstituteData` attribute, ensure that both `xunit` and `xunit.extensibility.core` packages are set to version **2.9.0**.
9-
> This is because the latest versions of xUnit are currently incompatible with `MemberAutoNSubstituteData` due to an unresolved issue. Although [xunit/xunit#3031](https://github.com/xunit/xunit/issues/3031) has been closed, the problem remains unresolved.
10-
> Upgrading beyond version 2.9.0 may result in test failures or unexpected behavior.
32+
`Atc.Test` depends on `xunit.v3.extensibility.core` for the extensibility APIs, but it intentionally does NOT bring in the `xunit.v3` meta-package for you.
33+
34+
### Why you must still reference xUnit directly
35+
36+
We do not make `xunit.v3` transitive because:
37+
38+
- The `xunit.v3` meta-package pulls in runner-related assets that are not targeted for `netstandard2.1`; this causes NU1701 framework fallback warnings if we referenced it from the multi-targeted library.
39+
- Consumers should control the exact xUnit version (pin or float) in their test project without the library forcing an upgrade cadence.
40+
- Keeping test framework + runner packages at the application (test project) layer avoids unexpected breaking changes when updating `Atc.Test`.
41+
- Separation of concerns: `Atc.Test` provides data attributes/utilities; the test project owns the choice of framework + runner configuration.
42+
43+
If you need a different xUnit patch/minor version, just adjust the `<PackageReference Include="xunit.v3" ... />` in your test project.
1144

1245

1346
## Test Attributes
@@ -18,8 +51,45 @@ Common tools for writing tests using XUnit, AutoFixture, NSubstitute and FluentA
1851
| `InlineAutoNSubstituteData` | Provides a data source for a data theory, with the data coming from inline values combined with auto-generated data specimens generated by AutoFixture and NSubstitute.|
1952
| `MemberAutoNSubstituteData` | Provides a data source for a data theory, with the data coming from one of the following sources and combined with auto-generated data specimens generated by AutoFixture and NSubstitute.|
2053

54+
### Usage Examples
55+
56+
```csharp
57+
public class CalculatorTests
58+
{
59+
[Theory]
60+
[AutoNSubstituteData]
61+
public void AutoData_Generates_Specimens(int a, int b, Calculator sut)
62+
{
63+
var result = sut.Add(a, b);
64+
result.Should().Be(a + b);
65+
}
66+
67+
[Theory]
68+
[InlineAutoNSubstituteData(2, 3)]
69+
public void InlineAutoData_Mixes_Inline_And_Auto(int a, int b, Calculator sut)
70+
{
71+
sut.Add(a, b).Should().Be(5);
72+
}
73+
74+
public static IEnumerable<object?[]> MemberSource()
75+
{
76+
yield return new object?[] { 1, 2 };
77+
yield return new object?[] { 10, 20 };
78+
}
79+
80+
[Theory]
81+
[MemberAutoNSubstituteData(nameof(MemberSource))]
82+
public void MemberAutoData_Augments_Member_Data(int a, int b, Calculator sut)
83+
{
84+
sut.Add(a, b).Should().Be(a + b);
85+
}
86+
}
87+
```
88+
89+
All remaining parameters (after those satisfied by inline/member data) are populated using an AutoFixture `IFixture` customized with NSubstitute for interfaces/abstract classes.
90+
2191
> **Note:**
22-
> NSubstitute is used when the type being created is abstract, or when the `[Substitute]` is applied.
92+
> NSubstitute is used when the type being created is an interface or abstract class.
2393
2494
## Test Helpers
2595

@@ -33,7 +103,7 @@ Common tools for writing tests using XUnit, AutoFixture, NSubstitute and FluentA
33103

34104
## Extensibility
35105

36-
The default `Fixture` returned by the `FixtrueFactory.Create()` method is used for all the `Attributes` mentioned above.
106+
The default `Fixture` returned by the `FixtureFactory.Create()` method is used for all the attributes mentioned above.
37107

38108
To add customizations to this, you can add the `AutoRegisterAttribute` to any custom `ICustomization` or `ISpecimenBuilder` to have it automatically added to the Fixture.
39109

0 commit comments

Comments
 (0)