Android 自動化測試遇到的問題總結


      在開發android自動化測試過程中,遇到了一些問題,這些問題總結如下:

       今天做android項目的單元測試時,使用Android Junit Test是,發現console日誌裏面拋出瞭如下問題:
 Test run failed: Test run failed to complete. Expected 1 tests, received 0
在google裏面尋找了好久,通過自己不懈努力,終於找到了解決問題的辦法:
我一一檢查是不是自己沒有功能配置文件中加入:

<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="你的單元測試所在包名" android:name="android.test.InstrumentationTestRunner" />,和<uses-library android:name="android.test.runner" />,自己也加入了,可就是產行,

我把那個單元測試方法寫了private權限,我一直以爲這樣寫應該沒有什麼問題,在我幾乎想不到是哪裏有錯時,我試着把那個單元測試方法的private權限改了public權限,運行一看,好了,原來問題就在這個單元測試方法不能爲private權限,一定寫成public權限,要不就會報Test run failed: Test run failed to complete. Expected 1 tests, received 0錯誤,

下面 我簡單的總結一下android單元測試的一些要求吧,

1、你要實現單元測試的類必須得繼承AndroidTestCast類,

2、你單元測試中的那個方法必須以Test開頭:Test+你的方法名,

3、你運行這個單元測試類的方法,一定選中這個以Test開頭的方法,再單擊右鍵,選中Android JUnit Test方可,

4、在你的項目的功能配置文件中必須加入 <instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="你的單元測試所在包名" android:label="Tests for My App" />,這一行加在<application>節點外面,而<uses-library android:name="android.test.runner" />則要加在<application>裏面,組件節點外面,如<Activity>節點外面

5、你單元測試中的那個方法必須拋出異常 ,在你的方法加上:throws throwable、
6、使用結構體爲:空參數結構體,類型爲public

二、寫好的程序,運行起來,發現Warning: No instrumentation runner found for the launch, using android.test.InstrumentationTestRunner,解決方法如下:

單擊“Android JUnit Test”運行後會,會出現如下警告:   
It outputs Warning: No instrumentation runner found for the launch, using   
android.test.InstrumentationTestRunner.   
模擬器不能記住Androidmanifest的配置,在運行時需要重新設置運行配置,如下:   
1.在工程名字上點擊右鍵,選擇properties   
2.在Run/Debug setting中選擇要運行的工程名字,點擊右邊的Edit,會進入下面的界面,   
在 instrumentation runner後面的下拉列表中選擇:android.test.InstrumentationTestRunner   
3.重新運行該測試單元,則就不會出現上面的警告了。


三、出現如下異常:
    java.lang.NullPointerException
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:117)
at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:98)
at com.android.widget.WidgetTest.setUp(WidgetTest.java:39)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
    這個問題解決如下:

private finial static LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.android.test.ResultActivity";
初始值賦值錯誤。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章