费了些工夫,已配好,按记录留记录

按官网操作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 配置的更多相关文章

  1. Android studio下gradle Robolectric单元测试配置

    android studio下gradle Robolectric单元测试配置 1.Robolectric Robolectric是一个基于junit之上的单元测试框架.它并不依赖于Android提供 ...

  2. Android 单元测试(junit、mockito、robolectric)

    1.运用JUnit4 进行单元测试 首先在工程的 src 文件夹内创建 test 和 test/java 文件夹. 打开工程的 build.gradle(Module:app)文件,添加JUnit4依 ...

  3. 在Android Studio中用Gradle添加Robolectric

    我们用Robolectric测试的话需要在gradle中进行配置,国内的详细教程太过简易,而且很多是低版本下的配置方案.所以经过本人的仔细摸索,找到了现在高版本中的配置方案,主要还是参考了官网的配置教 ...

  4. robolectric环境的搭建

    最近在学习测试驱动开发(Test-Driven Development),测试驱动开始是极限编程的一种方式,提倡在真正编写代码之前先根据需求编写测试代码(当然这个测试代码是不可能通过的),然后根据测试 ...

  5. Configuring Robolectric

    There are numerous ways to customize how Robolectric behaves at runtime. Config Annotation The prima ...

  6. Robolectric 探索之路

    layout: post title: Roboletric探索之路,从抗拒到依赖 description: Roboletric Android Unit Testing category: blo ...

  7. Robolectric使用教程

    转载请标明出处:http://blog.csdn.net/shensky711/article/details/53561172 本文出自: [HansChen的博客] 概述 怎样使用 为项目加入依赖 ...

  8. Robolectric测试框架使用笔记

    1. 概述 Robolectric(http://robolectric.org/)是一款支持在桌面JVM模拟Android环境的测试框架,通过shadow包下的类来截取view.activity等类 ...

  9. android studio 创建项目的一些配置

    build.gradle文件 apply plugin: 'com.android.application' apply plugin: 'org.greenrobot.greendao' // 使用 ...

随机推荐

  1. apache配置域名指向

    <VirtualHost *:80>ServerAdmin webmaster@example.com ——管理员邮箱(可以随便写一个)DocumentRoot "/home/p ...

  2. python---str

    Python转义字符 \ (在行尾时) 续行符 \\ 反斜杠符号 \' 单引号 \" 双引号 \a 响铃 \b 退格(Backspace) \e 转义 \000 空 \n 换行 \v 纵向制 ...

  3. Hadoop学习17--yarn配置篇-内存管理

    这篇文章来自于:董的博客,记录备查 内存管理,主要是管理nodemanager上的物理内存和虚拟内存. YARN允许用户配置每个节点上可用的物理内存资源,注意,这里是“可用的”,因为一个节点上的内存会 ...

  4. 伯克利包过滤(Berkeley Packet Filter,BPF)语言

    libpcap支持一种功能非常强大的过滤语言——“伯克利包过滤”语法.使用BPF过滤规则,你可以确定该获取和检查哪些流量,忽略哪些流量.BPF让你能够通过比较第2.3.4层协议中各个数据字段值的方法对 ...

  5. Tomcat 配置 HTTPS双向认证

    Tomcat 配置 HTTPS 双向认证指引说明: � 本文档仅提供 Linux 操作系统下的指引 � 在阅读本指引前请您在 Linux 部署 JDK 和 Tomcatserver为了 Tomcat ...

  6. “NOT_IN”与“NULL”的邂逅

    今天处理了一个因“NOT IN”与“NULL”邂逅导致的问题,值得思考和总结,记录在此,供参考.(感谢John抛出的问题) 我们以实验的形式先再现一下这个问题,然后对其分析,最后给出几种解决方案. 1 ...

  7. RealtekRTL8111内建网卡-黑苹果之路

    真是服了这神一样的黑苹果.好不容易配好显卡,登陆appstore却报“无法验证您的设备或电脑”,查了一圈,又说要配网卡为en0的,有说要在clover中配FIXLAN的,最准确的是网卡必须是内建(Bu ...

  8. 性能测试框架Locust初学笔记

    Locust初探 Locust是一款类似于Jmeter开源负载测试工具,所不同的是它是用python实现,并支持python脚本. locust提供web ui界面,能够方便用户实时监控脚本运行状态. ...

  9. lisp 题目

    1.根据二叉树的中序,前序生成生成二叉树的后续 2.BFPRT算法

  10. Linq To DataSet

    private static void LinqToDataSet() { string sql = "select * from Advertising"; using (Dat ...