Robotium on APK files using Android studio

569 views
Skip to first unread message

Stanojko Markovik

unread,
Aug 9, 2015, 3:33:51 PM8/9/15
to Robotium Developers
Hello everyone,
I am trying to setup a project with Android studio for my QA team to start building blackbox automation tests using robotium.

So the idea is, the tester will get the APK from the build server, resign with the re-sign.jar utility I got from your site, and then
start their android studio to develop tests using Solo, (we plan to also get a license for the recorder, but first off step1 needs to work)
the idea is that I want them to be able to do complete blackbox testing.

However when I try to start a simple test, the test suite breaks and tells me that it cannot instantiate the class I am calling from the UI
Package names are all good, tests are failing due to the following error.

Could you help ?


This is my error log  :

 
08-09 18:49:56.627: I/ActivityManager(293): Force stopping package com.example.test uid=10066
08-09 18:49:56.627: I/ActivityManager(293): Start proc com.my_app_package.test for added application com.my_app_package.test: pid=2672 uid=10066 gids={1028}
08-09 18:49:56.635: W/dalvikvm(2672): Exception Ljava/lang/RuntimeException; thrown while initializing Lcom/my_app_package/test/ApplicationTest;
08-09 18:49:56.635: W/dalvikvm(2672): Class init failed in Constructor.constructNative (Lcom/my_app_package/test/ApplicationTest;)
08-09 18:49:56.635: D/AndroidRuntime(2672): Shutting down VM
08-09 18:49:56.635: W/dalvikvm(2672): threadid=1: thread exiting with uncaught exception (group=0xa62fc288)
08-09 18:49:56.639: D/AndroidRuntime(2664): Shutting down VM
08-09 18:49:56.639: D/dalvikvm(2664): GC_CONCURRENT freed 102K, 89% free 455K/4096K, paused 0ms+0ms, total 1ms
08-09 18:49:56.639: D/jdwp(2664): Got wake-up signal, bailing out of select
08-09 18:49:56.639: D/dalvikvm(2664): Debugger has detached; object registry had 1 entries
08-09 18:49:56.639: I/AndroidRuntime(2664): NOTE: attach of thread 'Binder_3' failed
08-09 18:49:56.639: E/AndroidRuntime(2672): FATAL EXCEPTION: main
08-09 18:49:56.639: E/AndroidRuntime(2672): java.lang.ExceptionInInitializerError
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.reflect.Constructor.constructNative(Native Method)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at junit.framework.TestSuite.createTest(TestSuite.java:61)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at junit.framework.TestSuite.addTestMethod(TestSuite.java:294)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:150)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at junit.framework.TestSuite.<init>(TestSuite.java:129)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:118)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.test.AndroidTestRunner.getTest(AndroidTestRunner.java:148)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:56)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:444)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:425)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4142)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.app.ActivityThread.access$1300(ActivityThread.java:130)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.os.Looper.loop(Looper.java:137)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.reflect.Method.invokeNative(Native Method)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.reflect.Method.invoke(Method.java:511)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at dalvik.system.NativeStart.main(Native Method)
08-09 18:49:56.639: E/AndroidRuntime(2672): Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.my_app_package.ui.activities.SplashScreen
08-09 18:49:56.639: E/AndroidRuntime(2672):     at com.my_app_package.test.ApplicationTest.<clinit>(ApplicationTest.java:15)
08-09 18:49:56.639: E/AndroidRuntime(2672):     ... 24 more
08-09 18:49:56.639: E/AndroidRuntime(2672): Caused by: java.lang.ClassNotFoundException: com.my_app_package.ui.activities.SplashScreen
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.Class.classForName(Native Method)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.Class.forName(Class.java:217)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.Class.forName(Class.java:172)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at com.example.test.ApplicationTest.<clinit>(ApplicationTest.java:13)
08-09 18:49:56.639: E/AndroidRuntime(2672):     ... 24 more
08-09 18:49:56.639: E/AndroidRuntime(2672): Caused by: java.lang.NoClassDefFoundError: com/my_app_package/ui/activities/SplashScreen
08-09 18:49:56.639: E/AndroidRuntime(2672):     ... 28 more
08-09 18:49:56.639: E/AndroidRuntime(2672): Caused by: java.lang.ClassNotFoundException: com.my_app_package.ui.activities.SplashScreen
08-09 18:49:56.639: E/AndroidRuntime(2672):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-09 18:49:56.639: E/AndroidRuntime(2672):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-09 18:49:56.639: E/AndroidRuntime(2672):     ... 28 more
08-09 18:49:56.639: W/ActivityManager(293): Error in app com.my_app_package.test running instrumentation ComponentInfo{com.my_app_package/android.test.InstrumentationTestRunner}:
08-09 18:49:56.639: W/ActivityManager(293):   java.lang.ClassNotFoundException
08-09 18:49:56.639: W/ActivityManager(293):   java.lang.ClassNotFoundException: com.my_app_package.ui.activities.SplashScreen
08-09 18:49:56.639: I/ActivityManager(293): Force stopping package com.my_app_package.test uid=10066

I have the following config :

Gradle Build file :
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc3"
    defaultConfig {
        applicationId "com.my_app_package.test"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
        testApplicationId "com.my_app_package"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:22.2.1'
    androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.4.1'
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AndroidManifest.xml file :
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.my_app_package.test" >
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="android.test.runner"/>
        <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />
    </application>
    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.my_app_package" />

</manifest>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ApplicationTest.java :
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.my_app_package.test;

import com.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;

public class ApplicationTest extends ActivityInstrumentationTestCase2 {

    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.my_app_package.ui.activities.SplashScreen";
    private static Class launcherActivityClass;
    static {

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

    public ApplicationTest() throws ClassNotFoundException {
        super(launcherActivityClass);
    }

    private Solo solo;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void testDisplayBlackBox() {
        assertEquals(true, false);
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
    }

}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

naveed

unread,
Aug 11, 2015, 4:06:30 AM8/11/15
to Robotium Developers
Hi, 

when you sync your project using gradle - what happened ? 

plus I am in between writing a tutorial to set up Robotium around studio, will be up soon. 



Naveed

Stanojko Markovik

unread,
Aug 11, 2015, 8:06:45 AM8/11/15
to Robotium Developers
Hey, 
gradle sync works like a charm, 
Can I get an early preview of the doc? 
I can help probably as I am working on setting up a standalone project for a blackbox app... 
Would it help if I modify my project to bind to facebook for example and send it to you ? 

Best, 
Tancho

naveed

unread,
Aug 12, 2015, 2:34:24 AM8/12/15
to Robotium Developers
Yap sure

Naveed

Stanojko Markovik

unread,
Aug 14, 2015, 8:39:24 PM8/14/15
to Robotium Developers

Hello Naveed, 
here you go 
I modified the project to work with Instagram, 
From what I can see as Android Studio doesn't have an explicit "run as instrumentation test" 
it's trying to uninstall com.instagram.android as it's comparing to it's own build number or something.. 
attached : the zip file with a single automated test... 

can I have the preview howto for setting it up with Studio? 

thanks
Tancho
AutomatedTests.zip

Stanojko Markovik

unread,
Aug 14, 2015, 8:39:24 PM8/14/15
to Robotium Developers
hey Naveed,

any updates on this?
could you help me run a blackbox (apk) test in robotium?
Best
Tancho

On Wednesday, August 12, 2015 at 8:34:24 AM UTC+2, naveed wrote:

naveed

unread,
Aug 16, 2015, 9:07:21 AM8/16/15
to Robotium Developers
In talk with Tancho already to fix this problem. 

Naveed

Roberto Crisanti

unread,
Aug 23, 2015, 11:10:12 PM8/23/15
to Robotium Developers
I'm interested in black box testing too (expecially setting up and running tests with Android Studio) can you point me to an updated tutorial?

Renas

unread,
Aug 24, 2015, 8:16:33 PM8/24/15
to robotium-...@googlegroups.com

We will add new tutorials for black box testing in Android Studio shortly. In the meantime I can recommend you to use a free trial of Robotium Recorder and see how it does it. Have a look at the build.gradle that Robotium Recorder generates for the test project.

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotium-develo...@googlegroups.com.
To post to this group, send email to robotium-...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotium-developers.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages