Skip to content

Getting Started

Darrell edited this page Dec 5, 2015 · 10 revisions
  1. In Visual Studio, add a new project, and select "Unit Test App" from the Android sub menu:

  2. In your new project, open "AndroidManifest.xml" and make a note of the package name - you will need this later.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="yourpackagename" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
	...
</manifest>
  1. Add the Xamarin.TestyDroid NuGet package to your Tests project. Found on NuGet here: https://www.nuget.org/packages/Xamarin.TestyDroid/

  2. Next, add a new class to your tests project that looks like this:


namespace Your.Default.Namespace
{
    [Instrumentation(Name = "your.default.namespace.TestInstrumentation")]
    public class TestInstrumentation : TestyDroid.Android.TestyDroidTestSuiteInstrumentation
    {  
        public TestInstrumentation(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
        {
        }

        protected override void AddTests()
        {             
            AddTest(Assembly.GetExecutingAssembly());
        }
    }  
}

Note: Adjust the namespace appropriately. The **important ** thing is the attribute above this class. The Name property of this attribute must be set to the namespace of this class, in lower case, plus the class name in the correct case!

Make a note of this value - will refer to this as the ClassPath

You will need the PackageName and the ClassPath as arguments to pass into TestyDroid.exe later.

The next steps you will most likely want to put in your automated build process (like Team City) etc:

  1. Do a release build of your tests project to produce it's APK file.

  2. Run Xamarin.TestyDroid.exe with the necessary arguments - it will launch an emulator, run all of your tests, and report the results..

You can run Xamarin.TestyDroid from the Package Manager Console in VS if you wish to test this:

Example (substitute arguments as necessary) - see README for decription of arguments.

TestyDroid.exe -e "C:\Program Files (x86)\Android\android-sdk\tools\emulator.exe" -d "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -f "src\YouTestsProject\bin\Release\your.tests.apk-Signed.apk" -i "AVD_GalaxyNexus_ToolsForApacheCordova" -n "package name" -c "your.default.namespace.TestInstrumentation" -w 120

When setting up a TeamCity build step to do this, remember to use the -r TeamCity argument so that TestyDroid will output test results in a TeamCity format. This will make them appear as a tab on the TeamCity ui.

Viewing the report file

If you aren't using Team City, you might like to view the report xml file that TestyDroid writes to the device.

The adb command for that is:

adb -s emulator-5554 shell cat /data/data/[your package name]/files/TestyDroid.Android.ReportBuilder.xml

Obviously, substitute emulator-5554 for your device name, and [your package name] with the package name of your apk.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.