在Android的测试项目参数JUnit测试 [英] Parameterized JUnit tests in Android test project
问题描述
当我的JUnit 3.x中创建参数测试的情况下,我通常创建的东西一个TestSuite像
When I create parameterized test cases in JUnit 3.x, I usually create a TestSuite with something like
public static Test suite() {
TestSuite s = new TestSuite();
for (int i = MIN; i < MAX; ++i) {
s.addTest(new MyTest(i));
}
}
本套件()
方法是从桌面命令行运行JUnit时,称为正确。当我试图与我的Android测试项目,测试不运行。如何让我的测试,在模拟器上运行吗?还是有不同的方式来创建参数测试Android的?
This suite()
method is called correctly when running JUnit from a desktop command-line. When I tried this with my Android test project, the tests don't run. How do I get my tests to run on the emulator? Or is there a different way to create parameterized tests for Android?
<打击> 更多的想法:
通常情况下我跑我的测试中使用命令行:
Typically I run my tests with the command line:
adb shell am instrument -w [-e class <fully qualified test class name>[#<test method name>()]] <Android package name>/android.test.InstrumentationTestRunner
这可以让我选择它测试从我的测试套件运行。理想的情况下,我想运行在这种方式的参数化测试以及。从@Appu评论的链接描述构建一个运行JUnit测试一个单独的应用程序。作为其中的一部分,这个程序有一个自定义的TestRunner。我可以很可能借用这些想法创造的TestRunner,我可以代替 android.test.InstrumentationTestRunner
使用。这似乎是很多工作的并不少见任务。我preFER不要重新发明轮子,如果已经有Android的API中类似的解决方案。有谁知道这样的事情?此外,其他替代解决方案会有所帮助。击>
This allows me to select which tests to run from my test suite. Ideally, I want to run the the parameterized tests in this way as well. The link in the comment from @Appu describes building a separate app that runs JUnit tests. As part of that, this app has a custom TestRunner. I can very likely borrow these ideas to create a TestRunner which I can use in place of android.test.InstrumentationTestRunner
. This seems like a lot of work for a not uncommon task. I prefer not to reinvent the wheel if there is already a similar solution in the Android API. Does anyone know of such a thing? Also, other alternative solutions will be helpful.
没关系,它看起来像@dtmilano已经张贴了这个作为一个答案......
Nevermind, it looks like @dtmilano already posted this as an answer...
推荐答案
您可以实现测试运行,以便能够将参数传递到Android测试。 见的例子在<一个href="http://stackoverflow.com/questions/14820175/how-to-pass-an-argument-to-a-android-junit-test/14821971#14821971">how将参数传递给机器人JUnit测试。
You can implement a test runner to be able to pass parameters to Android tests. See the example at how to pass an argument to a android junit test.
这篇关于在Android的测试项目参数JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!