2012-07-24 14 views
12

Prova ad avviare il test JUnit (robotium) per la mia app.Esecuzione test non riuscita: l'esecuzione del test non è stata completata. 1 test attesi, ricevuti 0

public class MainTest extends ActivityInstrumentationTestCase2<MainActivity> { 
    private Solo solo; 

    public MainTest() { 
     super("nix.android.contact", MainActivity.class);// TODO Auto-generated constructor stub 
    } 

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

    public void AddContact() { 
     solo.assertCurrentActivity("main", MainActivity.class); 
    } 
} 

Manifest

<instrumentation 
    android:name="android.test.InstrumentationTestRunner" 
    android:targetPackage="nix.android.contact" /> 

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

When I try run test, get in console:

Test run failed: Test run failed to complete. Expected 1 tests, received 0 

I try create other test for other app (very simple app) - works.

Thanks

risposta

1

The problem is in your call at

super("nix.android.contact", MainActivity.class); 

In my code I have

super("nix.android.contact", Class.forName("nix.android.contact.MainActivity")); 

I've also done it this way without have to name the Generic for the ActivityInstrumentationTestCase 2

public class TestApk extends ActivityInstrumentationTestCase2 { 

    private static final String TARGET_PACKAGE_ID = "nix.android.contact"; 
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "nix.android.contact.MainActivity"; 

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

    @SuppressWarnings("unchecked") 
    public TestApk() throws ClassNotFoundException { 
      super(TARGET_PACKAGE_ID, launcherActivityClass); 
    } 
1

I had the same error message. The problem was that my test method name needed to start with 'test'.

Eg: testMethod1() opere mentre method1Test() dà l'errore.

+0

Diritto. Tutti i metodi devono avere nomi con prefisso "test"! – Alex

+0

È uno scherzo? – Janosch

5

Ho avuto questo problema quando non avevo un costruttore no-args.

public class MainActivityTest extends 
    ActivityInstrumentationTestCase2<MainActivity_> { 

public MainActivityTest() { 
    super(MainActivity_.class); 
} 
... 
-2

Il nome di tutti i test deve iniziare con il prefisso "test".

0

Controllare che non si stia verificando un metodo da cui dipende il contructor del test ma che nulla nell'applicazione utilizza - logcat lamenterà una classe o un metodo mancanti dal pacchetto dell'applicazione.

Provare a disinstallare il pacchetto di destinazione, per verificare che non sia rimasto da una build alternativa (se, ad esempio, si utilizza Maven accanto a Eclipse).

0

ho avuto questo errore e ho risolto rimuovendo il parametro dal metodo di costruzione, è stato creato da procedura guidata Eclipse come:

public OptionsActivityTest(String name) { 

ho dovuto rimuovere il "String name" per fare il mio lavoro di test ancora.

Problemi correlati