Android 自动化测试遇到的问题总结

来源:互联网 发布:java二维阶梯数组定义 编辑:程序博客网 时间:2024/05/01 15:20


      在开发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";
初始值赋值错误。





原创粉丝点击