bjorncs
bjorncs

Reputation: 1270

Running unit tests on a Java sub-project in Android Studio

I am not able to run any JUnit test on a Gradle sub-project in Android Studio. This project does not rely on Android in any way, it uses only the Java Gradle plugin.

The Android Gradle project has the following folder structure:

settings.gradle lists the two sub-projects:

include ':app', ':backend'

The app folder contains an Android project. It's build.gradle file looks like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.6'
    }
}
apply plugin: 'android'
android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"
}
dependencies {
    compile project(':backend')
}

The backend folder contains a normal Java Gradle project, which app depends on. It's build.gradle file looks like this:

apply plugin: 'java'
repositories {
    mavenCentral()
}
dependencies {
    testCompile 'junit:junit:4.11'
}

The backend project has several unit tests located in src/test/java/... When I try to execute any of them, I get an error stating the Android Studio cannot find the test class:

Class not found: "com.test.DummyTest"
Process finished with exit code 1

Executing gradle test works as expected. Is there any configuration I have missed, or is it plain impossible to get the unit tests to work in Android Studio?

Upvotes: 8

Views: 3038

Answers (2)

bjorncs
bjorncs

Reputation: 1270

Support for running JUnit test in Java modules was added in version 0.3.6 of Android Studio: https://code.google.com/p/android/issues/detail?id=60916

Upvotes: 3

Wael Showair
Wael Showair

Reputation: 3102

1- If you are using Android Studio,It sounds like Gradle Unit Test Plugin is what you are searching for.

2- As an alternative, you may use The EAP of IntelliJ IDEA 13, which includes all of the Android Studio features except for the redesigned new project wizard and the App Engine cloud endpoints integration, is available now

Upvotes: 0

Related Questions