Configure your Xamarin Android app to be testable

Prerequsites:

  • Visual Studio 2015 or 2017 with installed "Modile development with .NET" workload

New install

  • Test Studio Mobile Android extension:
    1. Download the Test Studio Mobile extension for Android and unpack it
    2. Extract MobileTestingExtension.jar somewhere on your PC

Building the Xamarin bindings library:

1.  Start new Visual Studio project and select Templates->Android->Bindings Library (Android)

New Binding Library

2.  Add MobileTestingExtension.jar to project:

    Solution Explorer->Right click on 'Jars' folder->Add->Existing Item...    
    Navigate to MobileTestingExtension.jar and add it to the project.

Adding JAR to project

3.  Edit MobileTestingExtension.jar properties:

    In Solution Explorer select MobileTestingExtension.jar and change 'Build Action' to 'EmbeddedJar'

Configuring JAR

4.  Open project Properties and set Target Framework to be same as Target Framework of the application that will be tested.

Properties

5.  Ensure to set explicitly the Android Codegen Target in project Properties to jar2xml.

Codegen Target

6.  Build Bindings library. You probably will get some warning messages in output console, but the library should be build sucefully and ouputed DLL will be located at:

Visual Studio Projects\ClassLibrary\ClassLibrary\bin\Debug\ClassLibrary.dll

For more information about building Xamarin bindings library see: Creating Bindings Library

Configuring Xamarin application:

1.  Add Bindings Library to the project under test:

References

2.  Open AndroidManifest.xml for editing

AndroidManifest

3.  Add the following top-level instrumentation element which will be used as App-Identifier in Test Studio Mobile and change target package name to match your application package:

 <instrumentation
        android:name="com.telerik.testingextension.MobileTestingInstrumentation"
        android:targetPackage="Todo.Android"/>

Instrumentation

4.  Add the following activity element as a child of the application element:

<activity android:name="com.telerik.testingextension.EntryPoint"
        android:theme="@android:style/Theme.NoDisplay" >
    <intent-filter>
    <action android:name="com.telerik.testing.ACTION_AUTOMATE"/>
    <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Activity

5.  Your application is ready for testing.

For more information about recording and executing tests with Test Studio Mobile see: Test Studio Mobile Help