bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
Run the test and get exception: System.MissingFieldException: 'Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'.' on var cut = RenderComponent<Index>();
Example:
Testing the Index.razor component:
`@page "/"
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />`
With this test:
`using BlazorNet5BUnit.Pages;
using Bunit;
using FluentAssertions;
using Xunit;
namespace BlazorNet5BUnit.UnitTests.Pages
{
public class IndexTests : TestContext
{
[Fact]
public void Page_Should_Render()
{
// Arrange & Act
var cut = RenderComponent<Index>();
// Assert
cut.Find("h1").InnerHtml.Should().Be("Hello, world!");
}
}
}
`
Results in this output:
System.MissingFieldException: 'Field not found: 'Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame.FrameType'.'
Expected behavior:
The test should succeed.
Version info:- Library version: Unit Test Project cs file
Hi @roysurles, thanks for taking the time to report this. It should however be fixed in the latest release, that added support for .NET5, i.e. beta-11.
Describe the bug or question
var cut = RenderComponent<Index>();
Example: Testing the Index.razor component:
With this test:
Results in this output:
Expected behavior: The test should succeed.
Version info: - Library version: Unit Test Project cs file
- .NET Core/Blazor version: Blazor Wasm Project cs file
dotnet --info `PS C:\Users\rsurles> dotnet --info .NET SDK (reflecting any global.json): Version: 5.0.100 Commit: 5044b93829
Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.100\
Host (useful for support): Version: 5.0.0 Commit: cf258a14b7
.NET SDKs installed: 3.1.302 [C:\Program Files\dotnet\sdk] 5.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download PS C:\Users\rsurles>`