Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MaxFmi opened this issue Feb 21, 2023 · 3 comments
Open

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

MaxFmi opened this issue Feb 21, 2023 · 3 comments

Comments

@MaxFmi
Copy link

MaxFmi commented Feb 21, 2023

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.

@jonathanpeppers
Copy link
Owner

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

@VladislavAntonyuk
Copy link
Contributor

#72

@BurkusCat
Copy link

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants