【问题标题】:How can I run Android tests with sbt?如何使用 sbt 运行 Android 测试?
【发布时间】:2012-01-07 00:41:36
【问题描述】:

我为我的应用程序开发了一套用 Scala 编写的使用 Robotium 库的小型 Android 测试。该套件是一个标准的 Android JUnit 测试项目,如果从 Eclipse 启动,则可以成功运行。

我已经使用 sbt android-plugin 成功构建并运行了我的主要 Android 应用程序。主应用程序位于[ProjectDir]/src/main。我还能够成功地找到位于[ProjectDir]/tests/src/main 目录中的build my Android test application。我检查了模拟器,测试应用程序似乎已使用 android-plugin 的 tests/android:install-emulator 命令正确安装。但是,当我尝试通过sbt tests/android:test-emulator 运行测试项目时,我得到:

...
Test results for InstrumentationTestRunner=
Time: 0.001

OK (0 tests)

如何让 sbt android-plugin 识别项目包含 JUnit 测试并运行它们?

【问题讨论】:

    标签: android scala junit sbt sbt-android-plugin


    【解决方案1】:

    这里使用的命名约定与普通的 JUnit 相同,因此您需要将测试命名为 xxxTest.class。他们还需要扩展 TestCase(AndroidTestCase、InstrumentationTestCase 等...)。

    重申一下,eclipse 将运行如下命令:

    adb shell am instrument -w -e class com.android.foo.FooTest,com.android.foo.TooTest com.android.foo/android.test.InstrumentationTestRunner
    

    它将类名称附加到命令中,因此命名约定可能不适用。

    如果你从 sbt 运行,它会运行

    adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner
    

    它将在应用程序 com.android.foo 的包名下找到所有类,并以 someClassNameTest 结尾。

    【讨论】:

    • 你是说它对你有用吗?这些测试在 Eclipse 的 Junit Android 测试运行器中可以正常运行。我不知道类命名约定,但知道方法命名约定——它们的方法名称需要以“test”一词开头。我的测试扩展了一个自定义类TestFixture,它扩展了ActivityInstrumentationTestCase2
    猜你喜欢
    • 2015-03-26
    • 2014-04-07
    • 2012-06-18
    • 2023-03-26
    • 2023-03-20
    • 2014-06-14
    • 2020-02-22
    • 2012-12-02
    • 1970-01-01
    相关资源
    最近更新 更多