Android build tools 1.1.0, unit test folder?

I recently installed the latest google tools for my Android project:

buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.1.0' } } allprojects { repositories { jcenter() } } apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { applicationId "com.xxx" minSdkVersion 10 targetSdkVersion 21 versionCode 200 versionName "2.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } signingConfigs { debug { ... } release { ... } } buildTypes { release { ... } debug { ... } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' // ---- Tests with robolectric testCompile 'com.google.guava:guava:14.0.1' testCompile 'junit:junit:4.+' testCompile 'org.robolectric:robolectric:2.4' testCompile 'org.mockito:mockito-all:2.0.2-beta' // ---- Tests with Espresso androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') { exclude module: 'hamcrest-core' } androidTestCompile 'org.hamcrest:hamcrest-core:1.1' androidTestCompile 'org.hamcrest:hamcrest-integration:1.1' androidTestCompile 'org.hamcrest:hamcrest-library:1.1' androidTestCompile ('com.android.support.test:testing-support-lib:0.1') { exclude module: 'hamcrest-core' } androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0' androidTestCompile('junit:junit-dep:4.10') { exclude module: 'hamcrest-core' } } 

Where before I used com.github.jcandksolutions.gradle:android-unit-test:2.1.1 to run my robolectric tests in jvm. As google says for its new build tools: "New source folders recognized by unit tests: src / test / java, src / testDebug / java, src / testMyFlavor / java, etc." But, as you can see below, my test folder is not recognized as the source folder. It worked with com.github.jcandksolutions.gradle:android-unit-test:2.1.1 , but no more with the new build tools:

enter image description here

What am I missing here? Thanks you

+7
android android-gradle robolectric build-tools android-build
source share
4 answers

I found a solution that should switch between test artifacts in the left corner of the IDE. Only "Toolkit Tests for Android" is available on this screen, because I downgraded my tools for Android, but with tools 1.1.0+ you should see different types of tests for the IDE to recognize them as source folders.

enter image description here

+6
source share

I had a similar problem the other day, except that I was able to run Robolectric tests in Android Studio, but did not work from the command line. What worked for me is the following.

1) Run ./gradlew clean assembleDebug test (instead of just clean test )

(now he will find the source from the main packages, but I would instead have this problem )

2) Added this to the build.gradle file: android.sourceSets.test.java.srcDirs += "build/generated/source/r/debug"

+4
source share

Just follow http://tools.android.com/tech-docs/unit-testing-support to enable the experimental unit test and switch the test artifact to unit tests. then your unit test folder will be recognized.

when you have more problems, maybe this will help http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html

+3
source share

If this is useful, I will set up a boiler plate design that allows the use of unit tests and Espresso tests using switching options. You do not need to use third-party plugins with this.

https://github.com/hitherejoe/Android-Boilerplate

0
source share

All Articles