2012-07-24 17 views
12

0 uygulamam için JUnit test (robotium) başlatmak deneyin aldı. method1Test() ikenTest çalıştırılamadı: Test çalışması tamamlanamadı. Beklenen 1 testleri,

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

cevap

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() eserler hata veriyor.

+0

Sağ. Tüm yöntemlerin "test" önekiyle isimleri olmalı! – Alex

+0

Bu bir şaka mı? – Janosch

5

Hatalı bir kurucum olmadığında bu sorunu yaşadım.

public class MainActivityTest extends 
    ActivityInstrumentationTestCase2<MainActivity_> { 

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

Tüm testler adı öneki "test" ile başlamalıdır. Eğer testin contructor bağlıdır bir yöntem ama uygulamada hiçbir şeyin dışarı proguarding değiliz

0

Kontrol kullanır - logcat uygulamanız paketinden eksik sınıf veya yöntemi hakkında şikayet edecektir.

Başka bir yapıdan (örneğin, Eclipse ile birlikte Maven'i kullanmıyorsanız) kaldığını kontrol etmek için hedef paketi kaldırmayı deneyin.

0

bu hatayı vardı ve ben yapıcı yönteminden parametresini kaldırarak düzelttim, bu Eclipse sihirbazı tarafından oluşturulan: Sadece benim testleri çalışması için "Dize adı" kaldırmak zorunda

public OptionsActivityTest(String name) { 

tekrar.