我为我的应用程序开发了一小部分用Scala编写的Android测试,它使用了Robotium库。该套件适用于所有意图和目的,是标准的Android JUnit测试项目,如果从Eclipse启动,则可以成功运行。
我已经使用sbt android-plugin成功构建并运行我的主要Android应用程序。主要应用程序位于[ProjectDir]/src/main
。我还能够成功build my Android test application位于[ProjectDir]/tests/src/main
目录中。我检查了模拟器,测试应用程序似乎已经使用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测试并运行它们?
答案 0 :(得分: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结束。