Test run failed: Test run failed to complete. Expected 1 tests, received 0

来源:互联网 发布:安康软件开发公司 编辑:程序博客网 时间:2024/05/19 09:09

这个问题有几天了

         我的错误在于这个函数带参数了,去掉参数就好了

错误代码

public void TestChange(String newName, String newPhone, String oldName)
   throws Exception
 {
  insertDeleteChangeCheck = new InsertDeleteChangeCheck(getContext(),
    "yangming.db", null, 2);
  insertDeleteChangeCheck.change("yangming", "123yanging", "test--17");
 }

正确代码

public void TestChange() throws Exception
 {
  insertDeleteChangeCheck = new InsertDeleteChangeCheck(getContext(),
    "yangming.db", null, 2);
  insertDeleteChangeCheck.change("yangming", "123yanging", "test--17");
 }

-------------------------------------------------------------------------------------------------http://blog.csdn.net/henry121212/article/details/7834856

  今天在写弄一个单元测试的时候老是报 Test run failed: Test run failed to complete. Expected 1 tests, received 0错误,我在google中查了很多资料,有的说是得有一个空构造函数,我也这么做了,可是依然没有效果,

   我一一检查是不是自己没有功能配置文件中加入:

     <instrumentation android:name="android.test.InstrumentationTestRunner"
         android:targetPackage="你的单元测试所在包名" android:label="Tests for My App" />,和<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


0 0
原创粉丝点击