Robolectric 配置
费了些工夫,已配好,按记录留记录
按官网操作http://robolectric.org/getting-started/
1引包
testCompile "org.robolectric:robolectric:3.0" 示例
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.loopj.android:android-async-http:1.4.7'
compile 'com.jakewharton:butterknife:6.1.0'
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile files('libs/jsoup-1.8.3.jar')
compile 'junit:junit:4.12'
}
2edit configurations
editing the run configurations, Defaults -> JUnit and changing the working directory value to $MODULE_DIR$.
3添加JUnit(这一点官方没有说明)
editing the run configurations
左上角 按+号 添加选中JUnit
设置fock mode 为method
设置user pclasspath of module 选中要测试的module
设置Class(需要加注解,才能识别)
4在方法上右键goto test 新建测试,编写方法,加注解
示例
@RunWith(RobolectricGradleTestRunner.class)
public class netTest {
@Test
@Config(constants = BuildConfig.class)
public void testHttpCookieGet() throws Exception {
System.out.println("ssout3");
net n=new net();
n.HttpCookieGet();
System.out.println("ssout");
Log.w("wbody hello", "workd");
assertEquals("1","1");
}
}
注意引用
import com.mac.cdp.baidusign.BuildConfig; import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;
5执行报错
项目api版本为22
Robolectric does not support API level 22
改为
@Config(constants = BuildConfig.class,sdk = 21)
执行通过
6
目前Log 和system.out.print()都还打不出日志。
傻了,日志还是在 android monitor里,我还以为用这种测试不会启动 android
Robolectric 配置的更多相关文章
- Android studio下gradle Robolectric单元测试配置
android studio下gradle Robolectric单元测试配置 1.Robolectric Robolectric是一个基于junit之上的单元测试框架.它并不依赖于Android提供 ...
- Android 单元测试(junit、mockito、robolectric)
1.运用JUnit4 进行单元测试 首先在工程的 src 文件夹内创建 test 和 test/java 文件夹. 打开工程的 build.gradle(Module:app)文件,添加JUnit4依 ...
- 在Android Studio中用Gradle添加Robolectric
我们用Robolectric测试的话需要在gradle中进行配置,国内的详细教程太过简易,而且很多是低版本下的配置方案.所以经过本人的仔细摸索,找到了现在高版本中的配置方案,主要还是参考了官网的配置教 ...
- robolectric环境的搭建
最近在学习测试驱动开发(Test-Driven Development),测试驱动开始是极限编程的一种方式,提倡在真正编写代码之前先根据需求编写测试代码(当然这个测试代码是不可能通过的),然后根据测试 ...
- Configuring Robolectric
There are numerous ways to customize how Robolectric behaves at runtime. Config Annotation The prima ...
- Robolectric 探索之路
layout: post title: Roboletric探索之路,从抗拒到依赖 description: Roboletric Android Unit Testing category: blo ...
- Robolectric使用教程
转载请标明出处:http://blog.csdn.net/shensky711/article/details/53561172 本文出自: [HansChen的博客] 概述 怎样使用 为项目加入依赖 ...
- Robolectric测试框架使用笔记
1. 概述 Robolectric(http://robolectric.org/)是一款支持在桌面JVM模拟Android环境的测试框架,通过shadow包下的类来截取view.activity等类 ...
- android studio 创建项目的一些配置
build.gradle文件 apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' // 使用 ...
随机推荐
- ES(一): 架构及原理
Elasticsearch 是一个兼有搜索引擎和NoSQL数据库功能的开源系统,基于Java/Lucene构建,可以用于全文搜索,结构化搜索以及近实时分析.可以说Lucene是当今最先进,最高效的全功 ...
- WCF JSON DATETIME JSON.NET (Newtonsoft.Json.dll)
[DataMember] public DateTime? myTime { get; set; } var timeFormat = new JsonSerializerSettings() { D ...
- boost-asio-cpp-network-programming阅读笔记
第二章:boost.asio 的基本原理 网络api boost.asio的命名空间 IP地址 端点 sockets 同步错误代码 socket成员函数 其他注意事项 read/write/conne ...
- xml与json 介绍
一.JSON数据格式 1)概念:json是一种网络数据传输格式,有值/对象:{“A”:1,”B”:”2”…}词典:对象的序列:[,,,,,]数组两种数据类型 2)URLWithString 将字符串网 ...
- JVM参数(二)参数分类和即时(JIT)编译器诊断
在这个系列的第二部分,我来介绍一下HotSpot JVM提供的不同类别的参数.我同样会讨论一些关于JIT编译器诊断的有趣参数. JVM 参数分类 HotSpot JVM 提供了三类参数.第一类包括了标 ...
- 在共享DLL中使用MFC
使用VS2008,在项目属性中有一项MFC的使用,有三种设置: 1.使用标准Windows库 2.在共享DLL中使用MFC 3.在静态库中使用MFC 第一种顾名思义. ...
- 样例20-汽车SHOW
观看样例点这里 素材下载 1.设置场景大小为400*3002.执行:文件->导入->导入到库,选择需要的汽车图片文件,将其导入到库面板中3.按照同样的方式,在库面板中导入所需的背景音乐文件 ...
- Django views 中 View decorators
decorators(装饰器) 1. require_http_methods 在django.views.decorators.http中,可以用来限制请求的权限. require_http_met ...
- google快捷键
使用快捷键的好处不言自明,如果能过直接访问google自然有对应的帮助文档以供参考,不过为了方便起见,还是将自己觉得有用的信息收藏到自己访问无障碍的地方吧! 一:以下快捷键适用于Windo ...
- 解决GBK字符转UTF-8乱码问题
通过以下方法将GBK字符转成UTF-8编码格式的byte[]数组 package test; import java.io.UnsupportedEncodingException; public c ...