Reputation: 27374
This was originally a rant. I spent hours trying to get the simplest unit test running in my Android project in Android Studio and I'm shocked by how seemingly impossible this basic task is.
I've read plenty of answers but they all seem to point you towards using Robolectric to avoid running tests on the device. I don't really care if they do run on the device or not. Moreover, even getting Robolectric integrated into Android Studio is a complicated multi-step process that in the end didn't work for me.
So the question is - what is the simplest set of steps required to get the most trivial test (not depending on Android SDK) pass in Android Studio. Tests like this one, starting with New project
@Test
public void just_work_will_you() {
Assert.assertEquals(1 + 1, 2);
}
Upvotes: 4
Views: 1511
Reputation: 171
Unit tests run on a local JVM (without a need for a device or emulator) are supported in Android Studio since version 1.1 and Gradle 1.1.0-rc1.
For setup instructions see: http://tools.android.com/tech-docs/unit-testing-support
Examples: https://github.com/googlesamples/android-testing (and then /unittesting/BasicSample)
If you want JUnit4 support - checkout Testing Support Library https://developer.android.com/tools/testing-support-library/index.html
Upvotes: 5