2011-08-23 57 views
5

我想要爲我的Android應用程序獲得一些單元測試。我正在關注Android開發中心的Hello, Testing教程,但它給我的信息如下:單元測試Eclipse + jUnit上的Android應用程序 - 測試運行失敗:測試運行不完整。預計1測試,收到0

測試運行失敗:測試運行不完整。預計1次測試中,獲得0

下面的代碼,我有:

public class LoginTest extends ActivityInstrumentationTestCase2<Login> { 

Activity mActivity; 
EditText mLoginTxt; 
EditText mPwdTxt; 
Button mLoginBtn; 
Button mClearBtn; 

public LoginTest(String pkg, Class<Login> activityClass) { 
    super("pkg_name", Login.class); 
} 

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

public void testPreconditions() { 

} 

public void testClear() { 
    assertTrue(true); 
} 

這裏是控制檯輸出:

[2011-08-23 12:21:12 - <AppNameTest>] ------------------------------ 
[2011-08-23 12:21:12 - <AppNameTest>] Android Launch! 
[2011-08-23 12:21:12 - <AppNameTest>] adb is running normally. 
[2011-08-23 12:21:12 - <AppNameTest>] Performing android.test.InstrumentationTestRunner JUnit launch 
[2011-08-23 12:21:12 - <AppNameTest>] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'AndroidHDPI' 
[2011-08-23 12:21:14 - <AppNameTest>] Application already deployed. No need to reinstall. 
[2011-08-23 12:21:14 - <AppNameTest>] Project dependency found, installing: <AppName> 
[2011-08-23 12:21:16 - <AppNameTest>] Application already deployed. No need to reinstall. 
[2011-08-23 12:21:16 - <AppNameTest>] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 
[2011-08-23 12:21:18 - <AppNameTest>] Collecting test information 
[2011-08-23 12:21:20 - <AppNameTest>] Test run failed: Test run incomplete. Expected 1 tests, received 0 

而這裏的logcat的輸出:

08-23 12:28:41.905: DEBUG/AndroidRuntime(1092): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 
08-23 12:28:41.905: DEBUG/AndroidRuntime(1092): CheckJNI is ON 
08-23 12:28:42.155: DEBUG/AndroidRuntime(1092): --- registering native functions --- 
08-23 12:28:42.995: DEBUG/AndroidRuntime(1092): Shutting down VM 
08-23 12:28:43.005: DEBUG/dalvikvm(1092): Debugger has detached; object registry had 1 entries 
08-23 12:28:43.025: INFO/AndroidRuntime(1092): NOTE: attach of thread 'Binder Thread #3' failed 
08-23 12:28:43.625: DEBUG/AndroidRuntime(1100): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 
08-23 12:28:43.625: DEBUG/AndroidRuntime(1100): CheckJNI is ON 
08-23 12:28:43.876: DEBUG/AndroidRuntime(1100): --- registering native functions --- 
08-23 12:28:44.735: DEBUG/AndroidRuntime(1100): Shutting down VM 
08-23 12:28:44.745: DEBUG/dalvikvm(1100): Debugger has detached; object registry had 1 entries 
08-23 12:28:44.765: INFO/AndroidRuntime(1100): NOTE: attach of thread 'Binder Thread #3' failed 
08-23 12:28:45.385: DEBUG/AndroidRuntime(1108): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 
08-23 12:28:45.385: DEBUG/AndroidRuntime(1108): CheckJNI is ON 
08-23 12:28:45.645: DEBUG/AndroidRuntime(1108): --- registering native functions --- 
08-23 12:28:46.555: INFO/ActivityManager(59): Force stopping package com.PatientPoint.MCC uid=10038 
08-23 12:28:46.625: INFO/ActivityManager(59): Start proc <pkg_name> for added application <pkg_name>: pid=1114 uid=10038 gids={3003} 
08-23 12:28:47.196: INFO/TestRunner(1114): started: warning(junit.framework.TestSuite$1) 
08-23 12:28:47.236: INFO/ActivityManager(59): Force stopping package <pkg_name> uid=10038 
08-23 12:28:47.246: INFO/Process(59): Sending signal. PID: 1114 SIG: 9 
08-23 12:28:47.355: DEBUG/AndroidRuntime(1108): Shutting down VM 
08-23 12:28:47.375: DEBUG/jdwp(1108): Got wake-up signal, bailing out of select 
08-23 12:28:47.375: DEBUG/dalvikvm(1108): Debugger has detached; object registry had 1 entries 
08-23 12:28:47.415: INFO/AndroidRuntime(1108): NOTE: attach of thread 'Binder Thread #3' failed 

回答

9

好吧,看起來我正在使用錯誤的構造函數。我做了日食自動生成的代碼,並創造了這個:

public LoginTest(String pkg, Class<Login> activityClass) { 
    super(pkg, Login.class); 
} 

然而,在將其更改爲這樣:

public LoginTest() { 
    super("pkg_name", Login.class); 
} 

它工作正常。但我不確定爲什麼,如果有人能提供解釋,我很樂意接受這個答案。對於遇到此錯誤的其他人,所有關於此問題的在線討論似乎表明您的構造函數中存在一些錯誤。

+0

謝謝,它幫助.. – FireAndIce

1

我已刪除參數,現在這是工作嘗試它。

public class LoginTest extends ActivityInstrumentationTestCase2<Login> { 

Activity mActivity; 
EditText mLoginTxt; 
EditText mPwdTxt; 
Button mLoginBtn; 
Button mClearBtn; 

public LoginTest() { 
super("pkg_name", Login.class); 
} 

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

public void testPreconditions() { 

} 

public void testClear() { 
assertTrue(true); 
} 
相關問題