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 ...
随机推荐
- Codeforces Round #154 (Div. 2) : B
一个很简单的题: 方法一: 二分. 代码: #include<cstdio> #include<algorithm> #define maxn 100005 using nam ...
- spoj PARTIT
三维DP 第K字典序从左向右找 根据dp数组的值算出每一位该打印什么 代码: #include <cstdio> #include <cstring> using namesp ...
- edgejs
http://krasimirtsonev.com/blog/article/Real-time-chat-with-NodeJS-Socketio-and-ExpressJS https://git ...
- 面试:如何找出字符串的字典序全排列的第N种
1.题目 如何找出字符串的字典序全排列的第N种?(字符串全排列的变种) 2.思路 主要想通过这题,介绍一下康托展开式.基于康托展开式可以解决这个问题. 一般的解法:①求出所有全排列 ②按照字典序排个序 ...
- 【转】LaTeX 符号命令大全
函数.符号及特殊字符 声调 语法 效果 语法 效果 语法 效果 \bar{x} \acute{\eta} \check{\alpha} \grave{\eta} \breve{a} \ddot{y} ...
- Delphi WebService 中 Web App Debugger 的建议
NEW一个WEBAPP,选WEBAPPDEBUGGER,输一个COCLASSNAME,比如叫HELLO保存为工程比如叫TEST,UNIT2比如改叫WEBMOD,UNIT1以后没用了,所以还叫UNIT1 ...
- 游戏开发设计模式之状态模式 & 有限状态机 & c#委托事件(unity3d 示例实现)
命令模式:游戏开发设计模式之命令模式(unity3d 示例实现) 对象池模式:游戏开发设计模式之对象池模式(unity3d 示例实现) 原型模式:游戏开发设计模式之原型模式 & unity3d ...
- 【转】Unity3D NGUI事件 UIEvents
原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 QQ群:[119706192] 本文链接地址: Unity3D NGUI事件 UIEvents UIEvents-事件系统void OnH ...
- Import larger wordpress xml file
The maximum size is controlled by two PHP settings: upload_max_filesize, and post_max_size. These ar ...
- Google协作平台
本博文的主要内容有 .Google协作平台的介绍 1.Google协作平台的介绍 https://zh.wikipedia.org/wiki/Google%E5%8D%8F%E4%BD%9C%E5%B ...