Blog Back to all posts View all authors

Test any mobile app - project configuration for AppCenter

by Gabriel Dudek
June 08. 2018

The whole code is finally working? Now it is test time! How to do this the right way?
Testing mobile apps on one device is not efficient. Buying hundreds of them generates enormous costs. Fortunately, there is one solution to both issues - AppCenter!
It is a platform that lets you see how the application looks and runs on various devices, without the need of purchasing them. Both on Android and iOS. You can be sure that your testing is going to be complex.
I have found out about this platform form one forum and decided to try it out during one of our mobile app projects. It was the first "device farm" used by me and the one I prefer working with.
To use AppCenter you have to configure your mobile app project first. How to do this? Let me guide you!

Before starting, make sure you have properly installed:

 

 Node.js

 Visual Studio with plugins supporting Xamarin UI Test

 

Checked? Great, let's move on to the actual steps!

Adding your app to the AppCenter

To test your app, you need to make an account in this Microsoft Service. After signing up, click Add new -> Add new app (upper right corner). A list is going to appear. Fill it in and, again, click Add new app.
Attention! You need to make this step twice. One project concerns devices with Android system and the other one with iOS.

 

To run the app, you need to install appcenter-cli. Do this by running a command line node.js, paste:


npm install -g appcenter-cli


and confirm with ENTER.

Preparing projects for tests in Visual Studio

The first step in Visual is adding UI test to our project. To do this, click with right button on the folder and choose Add.. -> New project. Then choose option picked in the picture below (Visual C# -> Test-> Xamarin.UITest Cross-Platform Test Project)  and click "OK".
Congratulations! The project has already been added to the solutions!

 

 

Another step is adding references to the project with tests. To do this, click the right button and choose Add -> References… and add references from Android and iOS to the project.

Next, for Android and iOS projects and your tests, add following NuGet packages:

 

UiTest 2.2.2

Microsoft.AppCenter.Analytics

Microsoft.AppCenter.Crashes

 NUnit 2.6.4

 

You need to remember that to install additional NuGet for iOS project, which is: 


Xamarin.TestCloud.Agent

In Android settings, mark out Use Shared Runtime.

 

 

In Android Manifest, pick INTERNET.

 

 

First, go to the App.xaml.cs. Add there:


using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;


In OnStart() method add a line:


AppCenter.Start("ios={Your iOS App secret here}" + "uwp={Your UWP App secret here};" + "android={Your Android App secret here}", typeof(Analytics), typeof(Crashes))

The next file you need to edit is AppDelegate.cs. Add there (to the "using"):


using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;

In the method FinishedLaunching() add the following line:


AppCenter.Start("App secret here ", typeof(Analytics), typeof(Crashes));

Finally, the last file to modify - MainActivity.cs! Add to "using":


using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;

In the method OnCreate() add the line:


AppCenter.Start("App secret here ", typeof(Analytics), typeof(Crashes));

Where to find APP SECRET? It is in the settings on the AppCenter website. It is also in the bookmark "Getting started". Remember, both for Android and iOS "app secret" is going to be different.

Now move on to the Tests.cs file and create app tests. After finishing writing tests, compile solutions and create an app with the extension .apk (Android) or .ipa (iOS).


Attention! Since March 31, 2018, Xamarin Test Recorder has been unavailable!
https://marketplace.visualstudio.com/items?itemName=XamarinInc.XamarinTestRecorder2015

In iOS there is no Back button, the best way to solve this problem is forcing a click in the upper left corner because that is usually the placing of a button allowing for going back. To do this, use TapCoordinates (Single x, Single y). You can gain these coordinates by turning off USB debugger and run additional option Show pointer location.

Running tests in AppCenter

Go to the AppCenter website. Depending on which platform you want to use for running tests, choose the proper project. From the side menu, choose the bookmark Test -> Test runs. Then in the upper right corner click New test run.
Choose the devices you want to youse and click Select device. As a Test framework, pick Xamarin.UITest and click Next.

In step two there is a text you have to copy:


appcenter test run uitest --app "xxx/xxx" --devices 7f211345 --app-path pathToFile.apk --test-series "xxx" --locale "en_US" --build-dir pathToUITestBuildDir


Change pathToFile.apk to the "path" to apk file, for example:


C:\App\App\ Droid\bin\Debug\App.apk


to


C:\App\App\ UITest\bin\Debug

Next, paste this line to the running node.js command line:


appcenter test run uitest --app "xxx/xxx" --devices 7f211345 --app-path C:\App\App\ Droid\bin\Debug\App.apk --test-series "xxx" --locale "en_US" --build-dir C:\App\App\ UITest\bin\Debug


Tests are running, their result will be presented on AppCentre for you to verify. Go and make your work smarter!

SEE ALSO

4 Hacks To Speed Up App Test 

contact us

Have an idea ? Let’s talk

Office in Rzeszow
Office in Warsaw
CONTACT US
CONTACT INFORMATION

GET IN TOUCH

Fill up the form and we will contact you shortly

Name
E-Mail
Message

Company information

Fill up the form and we will contact you shortly.

ServoCode Sp. z o.o.

Jasionka 954E, 36-002 Jasionka, Poland

NIP: 8133719852

REGON: 364182909

KRS: 0000611643

We are using cookies to provide statistics that help us give you the best experience of our site. You can find out more or switch them off if you prefer. However, by continuing to use the site without changing settings, you are agreeing to our use of cookies. Read more

close