Share this post
  

Get started with Xamarin Test Cloud

Let’s take a look to Xamarin’s Test Cloud and examine the basics for implementing automated UI Acceptance Testing for mobile application and explore the main features of this product.

Automating UI tests

At a glance, Xamarin Cloud Test allows you to automate UI Acceptance Testing by just following these steps:

  1. Setup the UI test-project with UITest in C# or Calabash (Ruby).
  2. Arrange, Act and Assert your tests.
  3. Submit and run your tests in the cloud.

Xamarin Test Cloud

1. Setup the UI test-project with UITest in C#

If you already familiar with Unit Testing in .Net, you can easily start your UI tests for your Xamarin Forms and scaffold the project by just indicating the name and location of your test project.

Now, UITest for C# is fully based on NUnit so if you are already familiar with it will be as easily as your normal Unit/Acceptance tests for other projects.

Here is how to add the project step by step with more details.

Target the platforms you need.

By having the project in place, you can just just add the reference and target both Android and iOS from a single cross-platform test suite.

You can take a sample from our repository in GitHub, where you can locate the prototyping app and the code for the UI tests as well.

Making our UITest cross-platform.

Since we are developing a cross-platform app, we can also make our tests to go cross-platform by just refactoring the code to make it run for other platforms as well. So let’s make a class that will abstract the application instance:


namespace Tests
{
    using NUnit.Framework;
    using Xamarin.UITest;

    public class CrossPlatformTests
    {
        protected IApp App { get; set; }

        [SetUp]
        public virtual void SetUp()
        {
            Assert.Ignore("This class requires a platform-specific bootstrapper to override the `SetUp` method");
        }
    }
}

By abstracting the application with the IApp member, it will allow you to have shared test suites for both Android and iOS.

2. Arrange, Act and Assert your tests

So by extending the previous class we are able to define the body of test to be run in every platform. Let’s add some basic tests to make sure our app is loaded the first time.

namespace Tests
{
    using NUnit.Framework;
    using System;
    using System.IO;
    using System.Reflection;
    using Xamarin.UITest;
    using Xamarin.UITest.Configuration;

    [TestFixture()]
    public class AndroidTest : CrossPlatformTests
    {
        [SetUp]
        public override void SetUp()
        {
            App = ConfigureApp.Android.StartApp();

            App.Screenshot("Given the app is loaded");
        }

        [Test]
        public void AppLaunches()
        {
            App.Screenshot("First screen.");
        }
    }
}

Then our new class can both contain both shared test-cases and add any platform-specific tests if necessary.

3. Submit your tests to the cloud.

Once you have the project in place, you can just start running your test cases right the way.

But before running the test suite in Xamarin Cloud, you need to make sure you’re deploying it in Release mode in Visual/Xamarin Studio to make it work.

Targeting devices to run.

After uploading, you will be prompted to select the number of devices to be run against your test suite that best fill your needs. After run, you can inspect the screenshots that we previously indicated as part of the test cases.

Here are the test results with the snapshots taken in every device:

{% asset_img test-suite-android.png Test-suite for Android %}

Here is how you can submit your tests step by step with more details.

Inspecting the results.

There you go! Your tests will start running and you will immediately receive the results as they execute. Additionally, you will receive an email after the tests are done.

{% asset_img tests-summary.png Test Summary %}

Here are the results for the sample app test run with the screenshots taken during the test executions.

{% asset_img tests-results.png Tests Results %}

And that’s it! Now we can focus on implementing more tests depending on application’s needs.

In further posts we will additional features of Xamarin Test Clould including REPL and deeper assertion cases.

Additional Xamarin resources.

Intro to Xamarin Test cloud Xamarin.UITest C# Cheat Sheet Code examples Working with REPL

Share this post
  


@stvansolano
More about me