Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Reqnroll BDD tests not working with a Blazor Maui Hybrid app

$
0
0

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 errorsThen 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="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /><!-- Splash Screen --><MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /><!-- Images --><MauiImage Include="Resources\Images\*" /><MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" /><!-- Custom Fonts --><MauiFont Include="Resources\Fonts\*" /><!-- Raw Assets (also remove the "Resources\Raw" prefix) --><MauiAsset Include="Resources\Raw\**" 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="..\TestForReqnroll\TestForReqnroll.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


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>