Is this a problem on Bunit or my project? #1336
-
We're upgrading our blazor application from net7 to net8 and our bunit tests no longer work. Here's the stacktrace on one of them:
I made sure to upgrade all the relevant libraries on the project: <ItemGroup>
<PackageReference Include="bunit" Version="1.26.64" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="moq" Version="4.20.70" />
<PackageReference Include="Moq.AutoMock" Version="3.5.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference> We had created this FallbackServiceProvider with Automocker, , which was working fine before the migration, that seems to be part of the cause: public class FallbackServiceProvider : IServiceProvider
{
private readonly AutoMocker _mocker;
public FallbackServiceProvider(AutoMocker mocker)
{
_mocker = mocker;
}
public object GetService(Type serviceType)
{
return _mocker.CreateInstance(serviceType);
}
} However, I'm puzzled that I got a "Did not find a best constructor for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @carbonell, Your problem is somewhat unrelated to bUnit itself. It is more or less a combination of Blazor and AutoMocker. Since .net8, the Renderer does the following: ServiceProviderCascadingValueSuppliers = serviceProvider.GetService<ICascadingValueSupplier>() is null
? Array.Empty<ICascadingValueSupplier>()
: serviceProvider.GetServices<ICascadingValueSupplier>().ToArray(); You can see this in your StackTrace that the c'tor of Bunits renderer ( To remove the issue, we can have a look at the proposal, where this functions was introduced: dotnet/aspnetcore#49104. Especially the code sample: // Registers an ICascadingValueSupplier that has IsFixed=true and always supplies this specific value, using the same CanSupplyValue rules as CascadingValue
services.AddCascadingValue(sp => new MyCascadedThing { Value = 123 }); With that we would have a |
Beta Was this translation helpful? Give feedback.
Hey @carbonell,
Your problem is somewhat unrelated to bUnit itself. It is more or less a combination of Blazor and AutoMocker. Since .net8, the Renderer does the following:
You can see this in your StackTrace that the c'tor of Bunits renderer (
WebTestRenderer
that inherits from the Blazor Renderer) is throwing the exception. This comes as AutoMocker tries to create a fake forICascadingValueSupplier
. And as it can't create an instance of that internal interface - …