Android Unit Testing in Eclipse: "Failed to launch test"

11,457

Solution 1

I was missing a TestSuite in my Test Project. Once I had my AllTests class extend TestSuite I got past the error.

Solution 2

For me the problem was that I was using JUnit 4. When I changed to JUnit 3 it started working. I hope this helps.

Share:
11,457

Related videos on Youtube

Peter Corke
Author by

Peter Corke

Software Engineer Amateur Photographer Father

Updated on February 27, 2020

Comments

  • Peter Corke
    Peter Corke about 4 years

    I've just started trying to set up some unit testing in what is essentially my first android app. I've had a hell of a time finding resource for this, but ultimately was able to scrape together what I hoped was the right path forward.

    First, this is what I've done.

    In Eclipse, I right-clicked my project that I'd like to create a test project for. I selected AndroidTools -> New Test Project I filled out the necessary information selecting a location of ../MyApp/tests for the new project and selected MyApp as the project to test. Everything else was left as default.

    While this was executing I received the below as an error:

    [2011-04-01 08:13:02 - WPMSTest] R.java was modified manually! Reverting to generated version!

    But everything seemed okay. I had a new source tree in my tests folder.

    So I tried to execute it (first on hardware, then on the emulator) by RunAs -> Android jUnit test.

    In both runs I received the below in my eclipse console:

    [2011-04-01 08:23:04 - WPMSTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554
    [2011-04-01 08:23:04 - WPMSTest] Failed to launch test

    My two manifest files:

    WPMSTest:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.WPMS.test"
      android:versionCode="1"
      android:versionName="1.0">
    
    <instrumentation android:targetPackage="com.WPMS" android:name="android.test.InstrumentationTestRunner" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    
    <uses-library android:name="android.test.runner" />
    </application>
    

    WPMS:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.WPMS"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher_wpms">
        <activity android:name=".WPMS"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>    
    
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    

    I'm hoping someone has seen something like this before and can shed some light on what I'm doing wrong. Please let me know if you need any more files and I'll be sure to post them.

    Thanks!

  • philgiese
    philgiese about 13 years
    As he is working in eclipse manual changes to the R-file should have no effect on his project, as the IDE will revert them anyway. Also it would be enough to do a full clean on the project, to have a brand new R-file generated.
  • Peter Corke
    Peter Corke about 13 years
    Yeah, I'm thinking that the R.java file problem isn't the whole issue - Knowing what that Failed to Launch is would be tremendous (App runs fine on the device without the test code)
  • idbrii
    idbrii almost 13 years
    This is probably common if you don't realise that Android doesn't support JUnit 4.
  • nhaarman
    nhaarman about 11 years
    @Siddharth Do you have any sources?
  • Siddharth
    Siddharth about 11 years
    I have put a simple source that illustrates Junit4 working on Android.
  • Ken
    Ken about 10 years
    JUnit 4 does work, but you have to use it like JUnit 3: class has to extend TestCase, method name has to start with "test", and @Test annotation does nothing (it cannot be resolved inside the emulator).
  • Rat-a-tat-a-tat Ratatouille
    Rat-a-tat-a-tat Ratatouille about 8 years
    @Ken - Is it true even today ?? I get the same error even if i use @Test annotation and espresso 2.2.1 and junit4. please advise what to do..

Related