2012-07-24 19 views
12

मेरे ऐप के लिए जुनीट टेस्ट (रोबोटियम) शुरू करने का प्रयास करें। जबकि method1Test()टेस्ट रन विफल: टेस्ट रन पूरा करने में विफल रहा। अपेक्षित 1 परीक्षण, 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); 
    } 
} 

प्रकट

<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

उत्तर

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() काम करता है त्रुटि देता है।

+0

दाएं। सभी विधियों में उपसर्ग "परीक्षण" के साथ नाम होना चाहिए! – Alex

+0

क्या यह एक मजाक है? – Janosch

5

मुझे यह समस्या थी जब मेरे पास नो-Args कन्स्ट्रक्टर नहीं था।

public class MainActivityTest extends 
    ActivityInstrumentationTestCase2<MainActivity_> { 

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

सभी परीक्षण नाम उपसर्ग "परीक्षण" से शुरू होना चाहिए।

0

जांचें कि आप इस विधि का प्रचार नहीं कर रहे हैं कि आपके परीक्षण के निर्माता पर निर्भर करता है लेकिन एप्लिकेशन उपयोग में कुछ भी नहीं - लॉगकैट आपके एप्लिकेशन पैकेज से गुम वर्ग या विधि के बारे में शिकायत करेगा।

लक्ष्य पैकेज को अनइंस्टॉल करने का प्रयास करें, यह जांचने के लिए कि यह वैकल्पिक निर्माण से नहीं छोड़ा गया है (उदाहरण के लिए, उदाहरण के लिए आप एक्लिप्स के साथ मेवेन का उपयोग करते हैं)।

0

मैं इस त्रुटि थी और मैं इसे निर्माता विधि से पैरामीटर को हटाने तय है, यह ग्रहण विज़ार्ड द्वारा बनाया गया था के रूप में:

public OptionsActivityTest(String name) { 

मैं बस अपना परीक्षण काम करने के लिए "स्ट्रिंग नाम" को दूर करने के लिए किया था फिर।