0

基本上,我想要实现的是这样的,但在 Ant 中使用 Robotium。我想使用 Ant 命令单独测试我的包(套件?)。

这样做的原因是因为应用程序的复杂性非常大,以至于当我一次运行所有内容时它会遇到问题,通常由于Robotium 遍历案例时的内存泄漏而中途终止,以及某些案例如何影响未来的案例应用程序某处的状态变化。

当只运行当前包或单独运行每个案例(使用我的 IDE)时,一切都运行良好,所以我想知道这是如何通过 Ant 实现的。

4

1 回答 1

1

我自己已经弄清楚了问题所在。它实际上非常简单,因为我模仿了 ant 测试的行为。

这个想法是,无论何时ant test运行,它都会简单地调用adb shell命令并触发检测测试运行器am instrument以及其他参数。可以自定义参数以定义要测试的类或包。

target解决方案是在执行此操作的custom_rules.xml(我使用它macrodef以便我可以将其重用于其他目标)上定义一个。

    <macrodef name="test-class">
    <attribute name="class"/>

    <sequential>
        <echo level="info">Running tests for @{class}</echo>
        <exec executable="${adb}" failonerror="false">
            <arg line="${adb.device.arg}"/>
            <arg value="shell"/>
            <arg value="am"/>
            <arg value="instrument"/>
            <arg value="-w"/>
            <arg value="-e"/>
            <arg value="class"/>
            <arg value="@{class}"/>
            <arg value="com.example.application/${test.runner}"/>
        </exec>
    </sequential>

</macrodef>

因此,如果您想要一个诸如 test-example 之类的 Ant 命令来测试 .tests.ExampleTest 测试用例,您可以这样定义它:

<target name="test-example">
     <test-class class="com.example.application.tests.ExampleTest />
</target>

然后运行它

ant clean debug install test-example 

要不就

ant test-example

哦,这不是 Robotium 独有的,因为 Robotium 实际上是基于 Android 提供的现有测试框架构建的。

于 2012-10-04T01:46:56.203 回答