简体   繁体   English

如何使用sbt运行Android测试?

[英]How can I run Android tests with sbt?

I developed for my application a small suite of Android tests written in Scala that uses the Robotium library. 我为我的应用程序开发了一小部分用Scala编写的Android测试,它使用了Robotium库。 The suite is for all intents and purposes a standard Android JUnit test project and runs successfully if launched from Eclipse. 该套件适用于所有目的和标准的Android JUnit测试项目,并且如果从Eclipse启动,则可以成功运行。

I've already successfully built and run my main Android application with sbt android-plugin. 我已经用sbt android-plugin成功构建并运行我的主要Android应用程序。 The main application is located in [ProjectDir]/src/main . 主应用程序位于[ProjectDir]/src/main I was also able to successfully build my Android test application that is located in the [ProjectDir]/tests/src/main directory. 我还能够成功构建位于[ProjectDir]/tests/src/main目录中的Android测试应用程序 I checked the emulator, and the test application appears to have been correctly installed with android-plugin's tests/android:install-emulator command. 我检查了模拟器,测试应用程序似乎已经正确安装了android-plugin的tests/android:install-emulator命令。 However, when I try to run the test project via sbt tests/android:test-emulator , I get: 但是,当我尝试通过sbt tests/android:test-emulator运行测试项目时,我得到:

...
Test results for InstrumentationTestRunner=
Time: 0.001

OK (0 tests)

How I can get sbt android-plugin to recognize that the project contains JUnit tests and run them? 我怎样才能让sbt android-plugin认识到该项目包含JUnit测试并运行它们?

The naming convention used here is the same as the normal JUnit and as such you need to name the tests xxxTest.class. 这里使用的命名约定与普通的JUnit相同,因此您需要将测试命名为xxxTest.class。 They also need to extend TestCase (AndroidTestCase, InstrumentationTestCase etc...). 他们还需要扩展TestCase(AndroidTestCase,InstrumentationTestCase等...)。

To reiterate, eclipse will run a command which will look like: 重申一下,eclipse将运行一个如下命令:

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

It will append the classes name to the command so naming convention might not apply. 它会将类名附加到命令中,因此命名约定可能不适用。

If you run from sbt, it will run 如果你从sbt运行,它将运行

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

which will find all the classes under the package name of the application com.android.foo which finishes with someClassNameTest. 它将找到应用程序com.android.foo的包名下的所有类,它们以someClassNameTest结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM