bunit.generators
1.33.1-preview
Prefix Reserved
See the version list below for details.
dotnet add package bunit.generators --version 1.33.1-preview
NuGet\Install-Package bunit.generators -Version 1.33.1-preview
<PackageReference Include="bunit.generators" Version="1.33.1-preview" />
paket add bunit.generators --version 1.33.1-preview
#r "nuget: bunit.generators, 1.33.1-preview"
// Install bunit.generators as a Cake Addin #addin nuget:?package=bunit.generators&version=1.33.1-preview&prerelease // Install bunit.generators as a Cake Tool #tool nuget:?package=bunit.generators&version=1.33.1-preview&prerelease
bUnit Generators
This package contains source generators for bUnit, to make it easier and more convenient to write tests.
AddStub
Generator
This generator adds the ability to automatically generate stubs for a given type with no setup involved. The generator sits on top of the already
present AddStub
method.
This comes in handy, when dealing with 3rd party components that might need an extensive setup. Here a small example:
Given the following component
<ThirdPartyText Text="@count" />
<button @onclick="IncrementCount">Increase by one</button>
@code {
private int count;
private void IncrementCount()
{
count++;
}
}
If ThirdPartyText
is a 3rd party component, that needs a lot of setup, it might be easier to just stub it out:
[Fact]
public void Text_button_gets_initial_count()
{
// This call will automatically generate a stub for the ThirdPartyButton component
// with the name "ThirdPartyButtonStub"
ComponentFactories.AddStub<ThirdPartyText>();
var cut = Render<Counter>(@<Counter />);
cut.Find("button").Click();
// Retrieves the stub from the render tree and checks if the text is "1"
cut.FindComponent<ThirdPartyTextStub>().Instance.Text.Should().Be("1");
}
Setup
To use the generator, the Interceptor feature has to be used inside the csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Bunit</InterceptorsPreviewNamespaces>
This limits the usage to .NET 8 and above.
ComponentStubAttribute
This generator adds the ability to automatically generate stubs for a given type via an attribute. The general setup for the given component above looks like this:
namespace MyTest;
public class FeatureTests : TestContext
{
[Fact]
public void Test()
{
ComponentFactories.Add<ThirdPartyText, ThirdPartyStub>();
...
}
}
[ComponentStub<ThirdPartyText>)]
internal partial class ThirdPartyStub { }
Current limitations of this approach:
- The stubbed type is not allowed to be nested inside the test class.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on bunit.generators:
Repository | Stars |
---|---|
linkdotnet/Blog
A blog (engine) completely written in C# and Blazor. It aims to be a simple use and easy to extend platform. Blogposts are written in Markdown and are rendered to HTML. This gives all the flexibility needed to express yourself but also have an easy way of creating posts in the first place.
|
Version | Downloads | Last updated |
---|---|---|
2.0.33-preview | 118 | 7/21/2024 |
2.0.24-preview | 1,241 | 3/13/2024 |
2.0.22-preview | 94 | 3/9/2024 |
1.36.0 | 88 | 11/12/2024 |
1.35.3 | 66 | 11/12/2024 |
1.33.1-preview | 62 | 10/7/2024 |
1.31.1-preview | 126 | 8/14/2024 |
1.28.4-preview | 106 | 3/17/2024 |
1.28.2-preview | 112 | 3/6/2024 |
1.27.16-preview | 100 | 3/2/2024 |
1.27.12-preview | 88 | 2/23/2024 |
1.27.11-preview | 129 | 2/19/2024 |
1.27.5-preview | 467 | 1/9/2024 |
1.27.2-preview | 443 | 12/28/2023 |
1.27.1-preview | 106 | 12/28/2023 |
1.26.61-preview | 91 | 12/17/2023 |
Changes in bUnit 1.33.1-preview
See the full changelog at https://github.com/bUnit-dev/bUnit/releases