12+ Jahre App-Entwicklung
Alles aus einer Hand
50+ Erfolgreiche App-Projekte

Blog

Automated UI-Tests made easy with Xamarin.UITest

As a developer we all know about that rumor of writing any kind of test is a costly task. In this post I would like to show you a better way for writing UI tests that even makes it fun when it comes to a very large mobile app.

Where Do We Come From?

To get a propper set of tests for an application we normaly have to specify what we want to test, we have to create the test cases, classes and what ever is involved to test our application.

With Xamarin Test Cloud you can fill your test cases with life through a REPL command line tool. With REPL you start navigating through your app by querying each screen for contained UI controls and later operate on them.

A simple test for a login button would look like this:

[TestFixture]
public class TelematicsDroidTest
{
    IApp _app;

    [Test]
    public void LoginAsDemoUser()
    {
        Func<AppQuery,AppQuery> demoLoginButton = e => e.Id("Logon_LoginDemo_Button");
        Func<AppQuery, AppQuery> mainFragmentContainer = e => e.Id("Main_FragmentContainer");

        _app.WaitForElement(demoLoginButton, "Timed out waiting for the Login_LoginDemo_Button to appear.");
        _app.Tap(demoLoginButton);
        _app.WaitForElement(mainFragmentContainer, "Timed out waiting for the Main_FragmentContainer to appear.");
        
        _app.Screenshot("Screennshot_after_press_Login_Button");
    }
}

What is not visible is the amount of time to get there. Remember, you normaly would test this with REPL first, later copy it into the test case, try it localy again and as the last step upload it to Xamarins Test Cloud. While this is easily understandable for software developers, a tester might not be into that kind of time consuming test creation process.

How Can We Improve This?

With the launch of Xamarin 4, which contains tons of improvements to the Xamarin ecosystem in general, comes my favorite feature called Xamarin Test Recorder.

Xamarin Test Recorder makes UI testing very easy no matter if you are at the beginning of UI testing or just want to have additional tests for your app. Why does it improve the creation of UI tests:

  • Point and click pattern makes it easy to create UI tests for people without programming knowlage
  • Write tests while manualy test the app
  • Good to use for small and big app projects
  • With Test Recorder you don't need to use the REPL tool.
Sebastian Seidel

Sebastian Seidel

Als Mobile-Enthusiast und Geschäftsführer der Cayas Software GmbH ist es mir ein großes Anliegen, mein Team und unsere Kunden zu unterstützen, neue potenziale zu entdecken und gemeinsam zu wachsen. Hier schreibe ich vor allem zur Entwicklung von Android und iOS-Apps mit Xamarin und .NET MAUI.

Verwandte Artikel

Erstellen eines .NET MAUI Karten-Steuerelements
Erstellen eines .NET MAUI Karten-Steuerelements

Ich arbeite derzeit an der Portierung einer Xamarin Forms App zu .NET MAUI. Die App verwendet auch Karten von Apple oder Google Maps, um Standorte anzuzeigen. Obwohl es bis zur Veröffentlichung von .NET 7 keine offizielle Unterstützung in MAUI gab, möchte ich Ihnen eine Möglichkeit zeigen, Karten über einen benutzerdefinierten Handler anzuzeigen.

App Design in 3 steps - an appealing ui design for a better ux
App Design in 3 steps - an appealing ui design for a better ux

Mobile apps thrive on an appealing and well-structured design that helps users achieve their goals. In this article, I'll show you how an old app design can be redesigned to make it look modern and clean. You'll learn more about the design process and design decisions made to provide users with a user-centric UI and UX that helps them achieve their goals.

3 alternatives to Xamarin.UITest
3 alternatives to Xamarin.UITest

UI testing is an essential part of mobile app development to ensure that the app delivers the best possible user experience and meets the needs and expectations of its users. But how do we do that in .NET MAUI when Xamarin.UITest is not fully compatible anymore? Let's look at 3 alternatives to Xamarin.UITest.