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 ...
随机推荐
- 写个自动下载安装Ant的shell脚本【二】
#!/bin/bash ####################################################### file name: install_ant.sh# # fun ...
- Spring整合CXF,发布RSETful 风格WebService
原文地址:http://www.cnblogs.com/hoojo/archive/2012/07/23/2605219.html 这篇文章是承接之前CXF整合Spring的这个项目示例的延伸,所以有 ...
- QImage与QPixmap加载图片效果(QImage不能拉伸图片,QPixmap默认拉伸图片)
QImage与QPixmap加载图片 效果 . 分类: QT开发 qtQtQT PixmapTest::PixmapTest(QWidget *parent) : QDialog(parent) {t ...
- 项目经验谈---IM新消息界面刷新异常处理记录
项目中使用到ContentObserver来观察Provider的变化,当对Uri做数据库操作时对应的Provider会发一条Notify消息调用UI上层的ContentChange方法,在这个Con ...
- android--使用Struts2服务端与android交互
一,服务器端: web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app vers ...
- lc面试准备:Implement Stack using Queues
1 题目 Implement the following operations of a stack using queues. push(x) -- Push element x onto stac ...
- bzoj2809
可以先穷举那个是管理者,然后就发现其实就是求每个子树选尽可能多的人,使薪水和小于m这显然是从小往大选,可以用启发式合并但是用主席树写的更简单一点吧,dfs序之后每课线段树不仅维护出现出现个数,然后在维 ...
- 【转】iOS开发入门:Xcode常用快捷键
原文网址:http://www.3g-edu.org/ios_free/3G-89.htm Xcode有许多快捷键,这些快捷键在Xcode的工具栏里都有标注,学会使用这些快捷键可以大大的提高你的编程效 ...
- Front-End Engineer 技术栈
自己根据各种招聘网站上的技术要求做的,希望自己能成为这样的人.
- Eclipse svn图标不显示
在菜单栏中:windows ->preferences->General->Appearance->Lable Decorations 勾选其中的 SVN 项,最后应用确认之后 ...