I am not familiar with any of the Android tests, but I see that you are trying to run basic unit tests.
Team:
./gradlew test
will run pure Java unit tests located in the src/test/java/ directory.
Pure Java test tests on Android
If you want to run unit tests of pure java without android dependencies, you can find them in the src/test/java directory and define them as follows:
@RunWith(JUnit4.class) public class SampleTest { @Test public void testKiraiShouldSetAnInputAndNotBeNull() {
In addition, your build.gradle file should have the following dependencies:
dependencies { testCompile 'junit:junit:4.12' testCompile('com.google.truth:truth:0.25') { exclude group: 'junit' // Android has JUnit built in } }
I use Google Truth for claims. This is a very convenient library. After that you can execute the command:
./gradlew test
and your tests should be performed. Alternatively, you can execute them through Android Studio.
If you want to see a full working example with pure java tests, you can check out one of my projects here: https://github.com/pwittchen/kirai .
Units Android dependency tests
If you want to create unit tests with Android dependencies (for example, using several classes from the Android SDK), you should find them in the following directory:
src/androidTest/
A sample test might look like this:
@RunWith(AndroidJUnit4.class) public final class SampleTest { @Test public void testKiraiShouldSetAnInputAndNotBeNull() {
Basically, the only difference from the previous sample is the @RunWith annotation value that defines the test runner, and the fact that you can use classes from the Android SDK here.
In the build.gradle file build.gradle you must define the following dependencies:
dependencies { androidTestCompile 'com.android.support.test:testing-support-lib:0.1' androidTestCompile('com.google.truth:truth:0.26') { exclude group: 'junit' // Android has JUnit built in. } }
In addition, you must define testInstrumentationRunner in the build.gradle file just like this:
android { defaultConfig { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } }
After that, you need to run the emulator of the Android device or connect a real-time Android device to it and enable debugging on it.
Then you can run the following command:
./gradlew connectedCheck
He will perform instrument cluster tests on a device or emulator. You can also run these tests from Android Studio.
If you want to see a full working example with unit tests with Android dependencies, you can check out my other project where I use this approach: https://github.com/pwittchen/prefser .
Automatic testing on Android can be confusing at the beginning, and I know your pain. Hope my post helps. :)