📜 ⬆️ ⬇️

DevOps in the service of man

Step by step, technologies take our jobs and threaten to get to the most valuable - Ctr-C from Stack Overflow and Ctrl-V in the native IDE. But fortunately, not a single neural network has yet learned to program better than you. Today we will talk about how you can use DevOps to get rid of the whole team of mobile developers and even you personally.




Note: we continue the series of publications of the full versions of articles from the magazine Hacker . Spelling and punctuation of the author saved.


Globally, DevOps solves the problem of maximum automation of everything that is reasonable to automate. The goal is simple - to reduce the time and cost of issuing or updating a product. This is a kind of another turn in increasing productivity and organizing, as it is sometimes said, “continuous supply of value to the client.”



At the moment, assembly, distribution and testing of new versions of the application are perfectly automated. In our article, we will show the process of building a Mobile DevOps universal pipeline consisting of the Bitrise.io build service , the Xamarin Test Cloud device farm, and the HockeyApp feedback system. As an experimental, we will use the Android application from the set of standard Java samples.



A remarkable feature of the modern world of online services is the presence of open APIs that allow building very convenient pipelines for processing your code into a high-quality product.


In order for the DevOps chain to start working, it needs to be configured, which we will do next. And first consider the algorithm of the pipeline in general:


  1. Any external event (a timer, a commit / pull-request / tag in the repository, a command from Slack, a button on the website, or something else) enlivens the whole chain.
  2. The build system, taking into account the settings, loads the latest or specified commit / branch from the repository, starts the build environment and issues the compiled / packaged application. For this purpose, a separate virtual machine with an already configured environment is deployed in Bitrise, and the necessary dependencies are loaded from the Web or from the cache before each build (Gradle, CocoaPods, NuGet). In addition to the basic verification of the code when compiling, you can also run Unit tests, which is important in mobile for long and heavy projects.
  3. Next, the application is unloaded into the file storage or external service. Bitrise allows you to host test builds on your servers and provides a direct page for downloading and installing into your phone.
  4. An assembly can also be uploaded to a cloud farm of devices for automated UI testing.

We create the pipeline


We begin, just in case, with a repository for storing source codes - it should be, and the point. You can use Bitbucket , GitHub or any other, but popular services are preferable because of the greater number of ready-made integrations. And it is better to use Git, as it is supported in almost all IDEs. We believe that the project (in our example, this is the classic Navigation Drawer from the Android SDK) has already been uploaded to Bitbucket, which, in turn, is connected to Bitrise.




We collect


The starting element of the DevOps chain is the build system. Here the taste and level of ownership of the admin tambourine comrades not. But Bitrise is one of the easiest and most functional options. It is inexpensive, works like a clock, allows you to fully build assemblies for projects on all popular mobile application development stacks: iOS + Obj-C / Swift, Android + Java, Xamarin (iOS + Android), Web App (PhoneGap, React Native and others) . And most importantly, Bitrise out of the box can configure integration with a large number of external systems.


To begin, register a free trial at Bitrise, create a new Android project in it, and link our repository. It is better to add keystore (and iOS certificates if you are developing for iPhone) to sign your application. It is better to run through the created Workflow for dating and learning.




Next, click the start button and after a while we get the finished assembly. You can immerse yourself in the logs to study the inside story of the whole process.



')

A large number of additional steps are available in Bitrise, which can be used by popular external services (including your favorite Slack). If you prefer, you can even write your own scripts (for example, to rename a package). And while no hassle with the infrastructure and its configuration and support! Assembly time, of course, will be slightly longer than on a good programmer's machine, but it allows you to continue working in parallel instead of the next coffee break. If necessary, Bitrise can even perform Unit tests for your project, again with the support of all popular platforms and stacks.


After a few minutes (and sometimes tens of minutes, depending on the complexity of the application), the assembly is ready, and we get a page for downloading the installation package to the smartphone. The link can be passed to all interested parties.




We are testing


One of the most problematic places in mobile development is strong fragmentation, not only in OS, screen size, price and color of the case, but also in OS versions, and for Android it is also in firmware versions for different models. Until recently, in decent mobile studios, we had to keep dozens (or even hundreds) of various devices and constantly monitor the fleet and firmware updates. The same application was rechecked on dozens of seemingly identical devices after each noticeable update or before publication. It remains to add the driver with a whip and a rare gnash of fingers on the screens ...


Fortunately, Apple and Google have not avoided this aspect by providing an API for automation in iOS and Android. That is, you can interact with the OS on a real device and simulate the user's work by executing scripts specified by the tester.


Different companies offer their farms of real devices for testing mobile solutions. We will focus on a universal and convenient service Xamarin Test Cloud. But before starting, we will have to conjure a little with the command line, as well as imbued with the spirit of Calabash .


We need to install Ruby, Ruby DevKit, additional gems and write our first script for Cucumber . Fortunately, any Google will show you step-by-step instructions, so we only note that the following gems are required:



The simplest script for our Navigation Drawer might look like this:




Yes, the script looks like an instruction not to a computer, but to a person. This is convenient for testers who do not really know how to program. But it is possible and necessary to use a more complex syntax, including indications of types of controls (picture, button) or screen coordinates. There can be an unlimited number of scripts, and they will be executed sequentially with a full restart of the application between them.


Before sending the installation package and scripts to an external cloud, it is better to run the written tests on a local smartphone or emulator / simulator (for example, using the calabash-android run command).


To work with Xamarin Test Cloud, we register the trial, and then proceed to creating the first run (Test Run).




From it we will need the device group identifier (specified after the --devices key) and API key (after the name of the APK file), which will be further used in Bitrise, adding a new step in our pipeline.



After successfully setting up the integration, we can run the script and in a few minutes look at the result of its work.






In addition to performing the tests themselves, Xamarin Test Cloud collects all system logs, resource consumption by the application, and even takes screenshots. After the test is completed, a detailed report becomes available, and you receive a notification by mail.


Xamarin Test Cloud will never replace real testers, as part of the errors can be identified only with manual long-term use of the application. But the cloud farm allows you to cool down the testing time and speed up the basic health check of all user scenarios. And the screenshots created during the execution of the script can help in finding UI errors at different resolutions and OS versions (buttons floated, texts are cut off, etc.).


A typical scenario for a large project is to run the timer at night or manually start a conveyor that includes automated UI testing of the current build (for fans, you can add Unit testing) on ​​the necessary smartphones / tablets and after a few hours (or in the morning) the quality control team A detailed report appears on the results of the run on a given sample of smartphones. However, it should be understood that there are relatively few devices (about 2500), and there are many who want it. Therefore, there are certain restrictions on the available subscription number of devices-hours per day. You need to be able to share ... especially if you're on trial.


We analyze


The last element of the pipeline is the service of receiving feedback (and in combination the distribution system). Now there are many libraries for collecting the most beautiful, statistics and user reviews. We will focus on the service HockeyApp.


First, let's add libraries to our project and initialize the HockeyApp in the mobile application. This is enough to make sure that no crash passes by us.




Unloading in HockeyApp is best done as a separate script that will be launched by a person after analyzing the results of the UI tests. There is even the ability to easily connect external freelancers to test your apps directly from HockeyApp.


We use


DevOps conveyors allow you to cover a very large fleet of devices, automate the assembly and testing of custom scripts on real smartphones and tablets of various manufacturers. Recently, universal integrated solutions (for example, the Microsoft Mobile Center) have begun to appear, allowing the use of automation advantages regardless of the selected mobile stack and platform.


Conclusion


In the article, we reviewed the creation of a pipeline based on Bitrise, Xamarin Test Cloud and HockeyApp, however you can pick up other tools or even deploy your own infrastructure. But here you can not do without the admin tambourine, and sometimes sweaters with a beard.


about the author



Vyacheslav Chernikov - head of development at Binwell . In the past, he was one of the Nokia Champion and Qt Certified Specialists, currently he is the Xamarin and Azure platform specialist. He came to the sphere of mobile in 2005, since 2008 he has been developing mobile applications: he started with Symbian, Maemo, Meego, Windows Mobile, then switched to iOS, Android and Windows Phone.


Articles Vyacheslav you can also read the blog on Medium .


Other articles by the author:



We remind you that this is the full version of an article from Hacker magazine .

Source: https://habr.com/ru/post/325184/


All Articles