Test run failed: Instrumentation run failed due to 'Process crashed.' when testing multiple Android activity
Asked Answered
B

4

14

I've got an issue with testing my android application.
I have 2 testCase class, if I execute them separately, there is no problem, the tests run until the end. But if I do "right-click" on my test project and choose "Run as Android Junit Test" I've got a message

 Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554
 [2012-03-27 15:56:27 - matroussedemaquillageTest] Collecting test information
 [2012-03-27 15:56:31 - matroussedemaquillageTest] Test run failed: Instrumentation run  failed due to 'Process crashed.'

see bellow for my two testClasses:

the first test class

package fr.smardine.matroussedemaquillage.test;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.ImageSwitcher;
import fr.smardine.matroussedemaquillage.EntryPoint;

public class EntryPointTest extends
    ActivityInstrumentationTestCase2<EntryPoint> {

private EntryPoint mActivity;
    private ImageSwitcher mSwitcher;

    public EntryPointTest() {
        super("fr.smardine.matroussedemaquillage",
                fr.smardine.matroussedemaquillage.EntryPoint.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void test2() {
        assertEquals(2, 2);
    }
}

and the second:

package fr.smardine.matroussedemaquillage.test;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.ImageView;
import fr.smardine.matroussedemaquillage.Main;

public class MainTest extends ActivityInstrumentationTestCase2<Main> {

    private Main mActivity;
    private ImageView btRemplir;
    private ImageView btPerime;
    private ImageView btNotes;

    public MainTest() {
        super("fr.smardine.matroussedemaquillage",
                fr.smardine.matroussedemaquillage.Main.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }


    public void test1() {
        assertEquals(1, 1);
    }
}

As you can see my test are not so complicated, even if i "wipe user data" when I launch my emulator, there is the same message if I execute the two tests.
Oh, by the way, the emulator run under android 2.1 and this is my AndroidManifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.smardine.matroussedemaquillage.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" />

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="fr.smardine.matroussedemaquillage" />

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

</manifest>

Edit: my log cat:

I/ActivityManager(64): Start proc fr.smardine.matroussedemaquillage for added application fr.smardine.matroussedemaquillage: pid=510 uid=10029 gids={3003, 1015} 
D/ddm-heap(510): Got feature list request D/dalvikvm(510): GC freed 5427 objects / 420224 bytes in 90ms 
D/dalvikvm(510): GC freed 6498 objects / 506616 bytes in 79ms 
D/dalvikvm(510): GC freed 7048 objects / 567464 bytes in 90ms 
D/dalvikvm(510): GC freed 8628 objects / 503840 bytes in 73ms 
I/System.out(510): Failed to open test.properties 
I/AndroidRuntime(510): AndroidRuntime onExit calling exit(-1) –
D/Zygote(30): Process 510 exited cleanly (255) 
I/ActivityManager(64): Process fr.smardine.matroussedemaquillage (pid 510) has died. 
W/ActivityManager(64): Crash of app fr.smardine.matroussedemaquillage running instrumentation ComponentInfo{fr.smardine.matroussedemaquillage.test/android.test.Instrumentatio‌​nTestRunner} 
D/ActivityManager(64): Uninstalling process fr.smardine.matroussedemaquillage
D/AndroidRuntime(504): Shutting down VM 
D/dalvikvm(504): DestroyJavaVM waiting for non-daemon threads to exit 
D/dalvikvm(504): DestroyJavaVM shutting VM down
D/dalvikvm(504): HeapWorker thread shutting down 
D/dalvikvm(504): HeapWorker thread has shut down 
D/jdwp(504): JDWP shutting down net... 
D/jdwp(504): Got wake-up signal, bailing out of select 
I/dalvikvm(504): Debugger has detached; object registry had 1 entries 
D/dalvikvm(504): VM cleaning up 
D/dalvikvm(504): LinearAlloc 0x0 used 643668 of 5242880 (12%) 
I/dalvikvm(504): JNI: AttachCurrentThread (from ???.???) 
E/AndroidRuntime(504): ERROR: thread attach failed'
Beverie answered 27/3, 2012 at 14:17 Comment(8)
Make sure these two activities under testing can properly started in the actual app under instrumenting (i.e no runTime exception leaked). Check out if you can get any more interesting message from Logcat.Ale
hi, thanks for your comment, the two activity under instrumenting are launched properly in the app. when i execute the app there is no exception. If i execute the two test separatly, there is no exception, the exception occur only if i execute the both testClass at same timeProceleusmatic
There should be more details shown in Logcat, when you get this message Instrumentation run failed due to 'Process crashed.' shown in Console. Post your Logcat would helps investigate your issue.Ale
Thanks for your help, i put my log cat at the end of the message's body.Proceleusmatic
I/System.out(510): Failed to open test.properties, How do you define and read test.properties in your app?Ale
that's the point, there is no file named test.properties in my app, neither in my test package. I don't know from where the emulator get this filename... Can it be a file automaticly generated by emulator when app or test package are launch at first time?Proceleusmatic
oups sorry for my late answer, yes my problem is solved. it was a problem of eclispe('s launch configuration. Thankds for your helpProceleusmatic
hello ..i also facing same problem, in my case I am starting service class from activity...if I put some delay to start service then it's working..but if it's start without any delay then it's giving erroe...any suggestion here?Maya
F
3

I used to get this error when I used System.exit(0) on my test Activity's onFinish like below:

@Override
    public void finish() {
        super.finish();
        System.exit(0);

    }

So check your Main activity's onFinish method.

Futuristic answered 12/10, 2012 at 11:32 Comment(0)
L
1

I encountered this error as well. However, I ended up finding that my test suite did run, the only problem was that an assert in my test code failed.

I looked into LogCat and filter out those Tagged "TestRunner" messages and found the assertion failure message among other testing logs.

Latarsha answered 22/4, 2013 at 18:49 Comment(0)
K
1

I also encountered similar problem when running my android instrumentation. Eventually i ended up with conclusion that the problem is of System.exit(0).

Now, the reason, why it causes the problem According to its documentation

Causes the VM to stop running and the program to exit.

When System.exit(0) gets executed all other code written after this code are skipped and activity class gets finalized and go for Garbage Collected. Since Instrumentation rely on activity life-cycle method, the activity class is Garbage collected the there is no chance of calling its methods if object itself does not exist.

Hence avoid using System.exit(0) if you want to do unit testing of application, use finish() method instead.

Kizer answered 4/8, 2014 at 11:14 Comment(0)
A
0

In case anyone else is also using Robotium and saw the error: I forgot to tearDown the opened activity, and this resulted in the error as described above.

public void tearDown() throws Exception {
    solo.finishOpenedActivities();
}
Arman answered 5/1, 2016 at 16:47 Comment(2)
what is "solo"?Contumelious
@Contumelious The Robotium instance, see github.com/RobotiumTech/robotium/wiki/Getting-StartedArman

© 2022 - 2024 — McMap. All rights reserved.