android-studio - android studio如何用AndroidTestCase测试呢?出错
阿神
阿神 2017-04-17 15:39:11
[Android讨论组]

按照这种教程,还是出很多问题

第一步:首先在AndroidManifest.xml中加入下面红色代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.lee0000.test" android:versionCode="1" android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">

    <uses-library android:name="android.test.runner"/> 

</application>

<use-sdk android:minSdkVersion="6"/>

<instrumentation android:name="android.test.instrumentationTestRunner" android:targetPackage="com.lee0000.test" android:label="Tests"/> 

 ***上面targetPackage指定的包要和应用的package相同。

出现问题是:
当新建如下程序的时候,出错:

package com.china.anonymous.demodemo;

import android.test.AndroidTestCase;

/**
 * Created by Anonymous on 2016/1/30.
 */
public class MyTest extends AndroidTestCase {


        public void show(){

                System.out.println("this is a get");
        }

}

java.lang.RuntimeException: Method setUp in android.test.AndroidTestCase not mocked

怎么回事呢?

阿神
阿神

闭关修行中......

全部回复(1)
大家讲道理

这个是android运行环境的问题,很简单的解决方法就是在
build.gradle添加下面 testOptions,如下:

android {
// ...
testOptions {

unitTests.returnDefaultValues = true

}
}

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号