运行在Android设备Robolectric测试的最佳方法 [英] Best way to run Robolectric tests on Android device

查看:261
本文介绍了运行在Android设备Robolectric测试的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Robolectric测试项目设置,但我想也跑我的设备上,这些测试来检查,我做得不到位由JVM VS的Dalvik实现差异。

I have a Robolectric test project setup, but I'd like to also run these tests on my device to check that I don't get bit by JVM vs Dalvik implementation differences.

不像robolectric测试,我不会频繁地运行这些测试。我担心的是,几乎没有精力来维护测试套件,他们确认实际设备的功能。

Unlike robolectric tests, I won't run these tests frequently. My concern is that there's little effort to maintain the test suite and that they verify actual device functionality.

什么是做到这一点的最好方法是什么?

What's the best way to do that?

我目前得到什么:

我的robolectric测试项目的测试情况TestPackage。我创建了一个测试案例TestRoboOnAndroid一个Android测试项目。它创建了一个TestPackage并有一个测试的TestPackage每个测试。

My robolectric test project as a test case TestPackage. I created an Android Test project with a test case TestRoboOnAndroid. It creates a TestPackage and has a test for each test in TestPackage.

现在,我每次测试添加到我robolectric套房,我需要手动将其添加到我的设备套件。是否有某种方式自动执行与反思?

Right now, every time I add a test to my robolectric suite, I need to manually add it to my device suite. Is there some way to do that automatically with reflection?

此外,Robolectric使用JUnit 4中(默认)和Android使用JUnit的3。所以我写的所有的使用JUnit 3样式(从 junit.framework 而不是 org.junit )。

Also, Robolectric uses JUnit 4 (by default) and Android uses JUnit 3. So I have to write all of my Robolectric tests using JUnit 3 style (importing from junit.framework instead of org.junit).

推荐答案

Robolectric的整点不是在设备上运行和设计是基于这一点。如果你想在从SDK默认的仪器测试运行的东西上的设备外观或 Robotium

The whole point of Robolectric is NOT to run it on the device and the design is based on that. If you want to run something on the device look at the default instrumentation tests from the SDK or Robotium.

这是运行在JVM上的Robolectric测试,另外创建依赖于特定设备的交互(例如创建截屏,硬件上的差异...)Robotium测试和运行设备和仿真全部合并为一个版本完全可行的。

It is totally feasible to run your Robolectric tests on the JVM and in addition create Robotium tests that rely on device specific interaction (e.g. creating screenshots, hardware differences...) and run on devices and emulators all combined into one build.

要做到这一点,最简单的方法是使用 Android的Maven插件

The easiest way to do that is to use the Android Maven Plugin.

这篇关于运行在Android设备Robolectric测试的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆