More information on how to write UI tests can be found in the official documentation: Using of AutomationId makes testing more robust, and also helps ensure fewer breaks in tests if developers will change the underlying controls.įigure 2. In the case of Xamarin.Forms, you need to set the AutomationId property (see Figure 2), which will be automatically assigned to the native AccessibilityIdentifier fields in iOS and ContentDescription on Android. To do this, you need to set the value in a specific field (see the documentation for test frameworks) on the UI component.
You should keep in mind that the tests may not only interact with the application as a black box, selecting items by the text or screen coordinates contained in them, but also click, for example, UI elements with internal identifiers specified in the source code. The main task that UI tests perform is the simulation of user actions on a real device: tapping the screen, data entry, gestures. In our example, we will focus on Xamarin.UITest for Android, which allows you to write test scripts in C#. Depending on which platform or framework you are developing (iOS, Android, Xamarin, ReactNative), you can use the following frameworks for testing:
Problems with the layout on all or some models of devices – an analysis of screenshots between different devices allows you to find errors in the interface, when something is cropped out, does not fit or is not displayed, etc.Īlso, UI testing saves the tester from the monotony of manual testing, manually performing the same tests on a large number of devices day-by-day. Inconsistency with the user interface behavior to the required scenarios – screen transition is not performed correctly or elements of the user interface don’t work In order to begin using automated UI testing in your development process, let’s define the types of problems that can be identified:Ĭrashes of the application on all or some devices, logs and crash-reports help to find the problems faster Here is a sample of appcenter-post-clone.sh (launch MSTest based unit tests for. To leverage this, you should launch unit tests on the “post-clone” step of your App Center build pipeline. This step will let you quickly detect changes and problems with external APIs used in the application. The Xamarin.Forms application architectureĪdditionally, you can cover integration to external REST-services with automated tests. Let’s look at the typical application architecture using Xamarin.Forms – Figure 1.įigure 1. If we consider a multi-layer architecture, common in mobile projects, we can distinguish the Data Access Layer (DAL, accessing to external online services or local database) which can be covered 100 percent with unit tests from the rest of the application. Most of the features require interaction with the user interface or platform functionality.
This article will help you learn how to more easily test Xamarin.Forms applications with MSTest based unit tests and Xamarin.UITest based UI tests.Īs I’ve covered in previous posts, it is not possible to cover all the code in mobile applications, as well as UI applications in general, with tests based on console Unit Tests. You can do both types of testing with your App Center CI/CD pipeline. Most mobile applications depend on the user interface and platform-specific features that make true Test-Driven Design (TDD) with solely unit tests extremely challenging So, it’s better to split automatic testing in two parts: cover the Data Access Layer with unit tests and cover the Business Logic, User Interface, and platform features with UI tests. As mentioned in my previous article “Mobile CI/CD 101” it’s not easy to cover an entire mobile application with just regular unit tests.
This is a guest blog by Slava Chernioff, Principal Engineer at Binwell.įrequent testing of your software is a key to success.