Customizing the Test Runner
There are several situations where you want to customize Robolectric's test runner to perform some operation before all tests are run, or even before each test method is run. One good example is initializing a dependency injection framework with a different set of dependencies for your test. Fortunately, Robolectric has a way to hook into the test lifecycle. If you define an Application class in your AndroidManifest.xml, Robolectric will automatically try and load a test version of your application class first. For example:
Let's say you've defined a FooApplication in your manifest:
<application android:name=".FooApplication">
If you're using RoboGuice, you would initialize the injector in your Application class:
public class FooApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ApplicationModule module = new ApplicationModule();
setBaseApplicationInjector(this, DEFAULT_STAGE, newDefaultRoboModule(this), module);
}
}
You can define a test version of the application named TestFooApplication:
public class TestFooApplication extends FooApplication implements TestLifecycleApplication {
@Override
public void onCreate() {
super.onCreate();
TestApplicationModule module = new TestApplicationModule();
setBaseApplicationInjector(this, DEFAULT_STAGE, newDefaultRoboModule(this), module);
}
@Override
public void beforeTest(Method method) {
}
@Override
public void prepareTest(Object test) {
getInjector(this).injectMembers(test);
}
@Override
public void afterTest(Method method) {
}
}
Robolectric will load the test version of the application which you can use to load a different set of bindings during tests.
Customizing the Test Runner的更多相关文章
- svn: E200007: Runner for 'org.tmatesoft.svn.core.wc2.SvnMerge' command have not been found; probably not yet implement in this API.
myeclipse分支合并主干(分支->team->合并->选择主干)的时候出现这个错误: svn: E200007: Runner for 'org.tmatesoft.svn.c ...
- 将 xunit.runner.dnx 的 xml 输出转换为 Nunit 格式
由于目前 DNX 缺乏 XSLT 的转换能力,因此只能使用变通方法.具体参考这个链接 主要内容复制过来是: From @eriklarko on July 14, 2015 7:38 As a wor ...
- postman使用之五:Runner的使用
1.首先在postman新建要批量运行的接口文件夹,新建一个接口,并设置好全局变量. 2.然后在Test里面设置好要断言的方法 如: tests["Status code is 200&qu ...
- 利用docker compose启动gitlab及runner
添加docker compose配置文件 新建文件docker-compose.yml,输入如下内容: gitlab: image: 'gitlab/gitlab-ce:latest' contain ...
- Task Runner Explorer for vs2015找不到啊
https://visualstudiogallery.msdn.microsoft.com/8e1b4368-4afb-467a-bc13-9650572db708/view/ 编译typescri ...
- karma作为jQuery单元测试Runner
karma作为angular测试runner出现,如果你使用过karma一定感受到这很不错的javascript测试runner.简单干净的配置文件karma.config.js,以及karma in ...
- exception throw in progress runner thread_VS2015中SVN源代码无说明提交异常
1-问题描述:通过SVN将代码变更提交服务器时,你可能会遇到以下异常: exception throw in progress runner thread 2-解决办法: SVN代码源代码管理和TF ...
- SaltStack之Job管理和Runner(八)
SaltStack之Job管理和Runner 配置文件/etc/salt/master cachedir: /var/cache/salt/master # cache路径 keep_jobs: 24 ...
- Customizing Navigation Bar and Status Bar
Like many of you, I have been very busy upgrading my apps to make them fit for iOS 7. The latest ver ...
随机推荐
- js一些方法的扩展
//JS扩展方法与C#的扩展方法非常相似,也是可以链式调用的,也是通过对某个类的扩展写法来实现.这个东西非常好用,如果将预先写好的方法放到一个js里面引用的话,那么后面写js将非常有趣. //下面给出 ...
- javascript学习代码
点击改变p和div元素: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...
- How Many Shortest Path
zoj2760:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2760 题意:给你一张有向带权图,然后问你最短路径有多少条. ...
- python functools模块
functools.partial 作用: functools.partial 通过包装手法,允许我们 "重新定义" 函数签名 用一些默认参数包装一个可调用对象,返回结果是可调用对 ...
- poj3167
这道题是一道kmp的扩展版的好题一串匹配一串很容易想到kmp,但是这里的匹配要求的是两个串的名次相同显然名次是会变的,为了方便,我们可以换一种表达对于两个等长的串的相同位置,名次相等就是在它之前比它小 ...
- Linux Shell编程(13)——数字常量
除非一个数字有特别的前缀或符号,否则shell脚本把它当成十进制的数.一个前缀为0的数字是八进制数.一个前缀为0x的数字是十六进制数.一个数用内嵌的#来求值则看成BASE#NUMBER(有范围和符号限 ...
- Oracle自动增长的序列号
首先建立序列: Create sequence user_id Increment Start Maxvalue .0E28 Minvalue nocycle Cache Noorder; 然后建立触 ...
- 从物理执行的角度透视spark Job
本博文主要内容: 1.再次思考pipeline 2.窄依赖物理执行内幕 3.宽依赖物理执行内幕 4.Job提交流程 一:再次思考pipeline 即使采用pipeline的方式,函数f对依赖的RDD中 ...
- 2014 牡丹江现场赛 i题 (zoj 3827 Information Entropy)
I - Information Entropy Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %l ...
- poj 1679 The Unique MST【次小生成树】
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24034 Accepted: 8535 D ...