简体   繁体   中英

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. The suite is for all intents and purposes a standard Android JUnit test project and runs successfully if launched from Eclipse.

I've already successfully built and run my main Android application with sbt android-plugin. The main application is located in [ProjectDir]/src/main . I was also able to successfully build my Android test application that is located in the [ProjectDir]/tests/src/main directory. I checked the emulator, and the test application appears to have been correctly installed with android-plugin's tests/android:install-emulator command. However, when I try to run the test project via sbt tests/android:test-emulator , I get:

...
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?

The naming convention used here is the same as the normal JUnit and as such you need to name the tests xxxTest.class. They also need to extend TestCase (AndroidTestCase, InstrumentationTestCase etc...).

To reiterate, eclipse will run a command which will look like:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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