I created a new Maui Blazor app with VS 2022. I have the Reqnroll plugin installed and created a new project within the solution. I added a project reference to the first Maui Blazor app just like the documentation states. (Reqnroll documentation)
I changed the TargetFrameworks in both projectfiles to “net8.0-windows10.0.19041.0”. I build both projects after making a dummy test which works as expected. (Both application also run without any issues) But when I run “dotnet test” in the terminal I get the following error:
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Given The class has been instantiated
-> error: The type initializer for '<Module>' threw an exception. (0,1s)
When The function is called
-> skipped because of previous errors
Then it should return true
-> skipped because of previous errors
Failed CallingTestFunction [231 ms]
Error Message:
System.TypeInitializationException : The type initializer for '<Module>' threw an exception.
----> System.TypeInitializationException : The type initializer for 'WinRT.ActivationFactory`1' threw an exception.
----> System.Runtime.InteropServices.COMException : Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
Stack Trace:
...
Here are my project files:
Maui Blazor
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>TestForReqnroll</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<EnableDefaultCssItems>false</EnableDefaultCssItems>
<Nullable>enable</Nullable>
<!-- Display name -->
<ApplicationTitle>TestForReqnroll</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.companyname.testforreqnroll</ApplicationId>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<Platforms>x64</Platforms>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Update="ResourcesAppIconappicon.svg" ForegroundFile="ResourcesAppIconappiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="ResourcesSplashsplash.svg" Color="#512BD4" BaseSize="128,128" />
<!-- Images -->
<MauiImage Include="ResourcesImages*" />
<MauiImage Update="ResourcesImagesdotnet_bot.svg" BaseSize="168,208" />
<!-- Custom Fonts -->
<MauiFont Include="ResourcesFonts*" />
<!-- Raw Assets (also remove the "ResourcesRaw" prefix) -->
<MauiAsset Include="ResourcesRaw**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>
</Project>
The test project
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFrameworks>net8.0-windows10.0.19041.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Platforms>x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Reqnroll.NUnit" Version="1.0.0" />
<PackageReference Include="nunit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Drivers" />
<Folder Include="Support" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..TestForReqnrollTestForReqnroll.csproj" />
</ItemGroup>
</Project>
Test step definition
using NUnit.Framework;
using TestForReqnroll.Components;
namespace TestForReqnroll.test.StepDefinitions
{
[Binding]
public class TestStepDefinitions
{
private testClass testClass;
[Given("The class has been instantiated")]
public void GivenTheClassHasBeenInstantiated()
{
testClass = new testClass();
}
[When("The function is called")]
public void WhenTheFunctionIsCalled()
{
testClass.testFunction();
}
[Then("it should return true")]
public void ThenItShouldReturnTrue()
{
Assert.AreEqual(true, true);
}
}
}
and a screenshot of my entire solution
ninjagast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.