Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 971
Jeff Axelrod Avatar asked Nov 26 '11 19:11

Jeff Axelrod


1 Answers

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.

like image 124
charroch Avatar answered Oct 20 '22 00:10

charroch