unit-testingtdd.net-8.0maui-blazor

Unit test framework for .net maui hybrid blazor app with .net 8 and target Android and Windows


I just wondered which unit test framework to use in a .NET MAUI Blazor Hybrid app with multiple targets like Android and Windows.

I already tried nUnit and xUnit, but it is not working out of the box. As soon as I reference my main project, I get multiple target related errors telling me that my .Net 8 x/nUnit project can not find some stuff out of Android/Windows target, as the are not also clean .Net8 applications.

Any experience with unit testing a hybrid app?


Solution

  • I now can answer the question by myself as simply as following:

            <TargetFrameworks>net8.0;net8.0-android;net8.0-windows10.0.19041.0</TargetFrameworks>
    

    what is this?: I just had to add to my main project under TargetFrameworks the .NET 8 Framework itselfe. this way my xUnit Testprojekt can pickup the net8.0 output and work with that. Tested and used, works like a charm. Found my answer in this blog: https://putridparrot.com/blog/unit-testing-your-maui-project/#:~:text=,following