Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - InstrumentationTestRunner

Tags:

android

I'm new to Android and a bit rusty on Java, coming from a .NET background. I'm developing some test automation for a mobile application running on Android.

Currently, I'm just launching the tests via the command line using the Android Debug Bridge, but I'm getting an error when I attempt to run any tests:

First off, this is the error I'm receiving:

junit.framework.TestSuite$1: Failure in warning: junit.framework.AssertionFailedError: No tests found in com.myapp.test.UITests at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

I'm using this adb command to attempt to launch the test (on a rooted device):

adb shell am instrument -e class com.myapp.test.UITests -w com.myapp.test/android.test.InstrumentationTestRunner

Finally, here is the class I'm attempting to run tests from:

package com.myapp.test;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import com.jayway.android.robotium.solo.Solo;
import junit.framework.Assert;

@SuppressWarnings("unchecked")
public class UITests extends ActivityInstrumentationTestCase2
{
    private static final String TARGET_PACKAGE_ID = "com.myapp.main";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.myapp.main.activities.MainActivity";
    private static Class<?> launcherActivityClass;

    private Solo solo;
    private Activity activity;

    static 
    {
        try
        {
            launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        }
        catch(ClassNotFoundException e)
        {
            throw new RuntimeException(e);
        }
    }

    public UITests() throws ClassNotFoundException
    {
        super(TARGET_PACKAGE_ID, launcherActivityClass);
    }

    @Override
    protected void setUp()
    {
        activity = getActivity();
        solo = new Solo(getInstrumentation(), activity);

    }

    @Override
    public void runTest() throws Throwable
    {
        // Simple Test
        Assert.assertTrue(solo.searchText("Welcome"));
    }

    @Override
    protected void tearDown() throws Exception
    {
        try
        {
            solo.finalize();
        }
        catch(Throwable e)
        {
        }
        getActivity().finish();
        super.tearDown();
    }

}

I must be doing something wrong, but I'm not sure what. I've based my code on an example I found on the Robotium site.

I'd greatly appreciate if anyone could point out my mistake.

Update - Adding Manifest file as requested

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.myapp.test"
          android:versionCode="1"
          android:versionName="1.0">

    <uses-sdk android:minSdkVersion="3" />

    <application android:icon="@drawable/icon" android:label="@string/ws_app_name">
        <uses-library android:name="android.test.runner" />
    </application>

    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="com.myapp.main"
                     android:label="My App Tests"/>
</manifest>
like image 914
Jimmy Collins Avatar asked Jan 07 '12 15:01

Jimmy Collins


1 Answers

I managed to figure this out, I didn't realize that each tests function name had to begin with 'test' as outlined here.

like image 115
Jimmy Collins Avatar answered Oct 08 '22 11:10

Jimmy Collins