Xamarin.Forms.Mocks icon indicating copy to clipboard operation
Xamarin.Forms.Mocks copied to clipboard

[Enhancement] Is there a version planned for .NET MAUI?

Open MaxFmi opened this issue 2 years ago • 3 comments

Hello @jonathanpeppers,

first of all, thank you for writing this tool. It helps us a lot when we write component and integration tests.

Is there a plan to have a similar tool for .NET MAUI? I haven't figured out how to write it myself. At least until now.

MaxFmi avatar Feb 21 '23 11:02 MaxFmi

I hadn't planned on doing anything here yet.

It might be possible to do it yourself already, you can look at MAUI's tests and copy what they do?

This is just a random example:

https://github.com/dotnet/maui/blob/main/src/Controls/tests/Core.UnitTests/ContentViewUnitTest.cs

jonathanpeppers avatar Feb 23 '23 21:02 jonathanpeppers

https://github.com/jonathanpeppers/Xamarin.Forms.Mocks/pull/72

VladislavAntonyuk avatar Sep 11 '23 05:09 VladislavAntonyuk

In case it helps anyone else as it did for some of my unit tests. This worked when I wanted to check some code that did things with resource dictionaries in App.Current and I had this in my test constructor (I previously also used this NuGet package in the constructor):

    public ExampleTest()
    {
        Application.Current = new App();
    }

Update your App.xaml.cs like to get the above test code to work.

public partial class App : Application
{
    public App()
    {
#if ANDROID || MACCATALYST || IOS || WINDOWS
        // don't call InitializeComponent in unit tests
        InitializeComponent();
#endif
    }

#if NET7_0_OR_GREATER && !ANDROID && !MACCATALYST && !IOS && !WINDOWS
    // workaround for unit tests in Maui https://github.com/dotnet/maui/issues/3552#issuecomment-1172606125
    public static void Main(string[] args) {}
#endif
}

BurkusCat avatar Oct 24 '23 17:10 BurkusCat