25

I'm attempting to set up a unit test module as described in the android studio blog post. However, doing a gradle build fails telling me "Configuration with name 'debug-classes' not found". Debug is the name of the targetVariant it's trying to build, but I don't understand what is going wrong here.

Here's my test module's gradle file.

apply plugin: 'com.android.test'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

targetProjectPath ':app'
targetVariant 'debug'
}    

This is the blogpost describing the new test module functionality. http://android-developers.blogspot.com/2015/07/get-your-hands-on-android-studio-13.html

I'm using the Gradle plugin v1.3.0

Brenton
  • 556
  • 1
  • 4
  • 13
  • Are you using Gradle plugin 1.3.0? – EpicPandaForce Aug 03 '15 at 05:54
  • Yeah, I am using it. I mentioned it in the title, but not the post itself. – Brenton Aug 03 '15 at 15:04
  • The issue seems to be that I'm using build flavors, so there's nothing called "deubg". However, on my first attempt, I couldn't fix the issue by pointing targetVariant at my build flavors. I'll look into this more shortly.... – Brenton Aug 04 '15 at 17:44
  • If you have product flavors, you may have to do `targetVariant ''` – Jared Burrows Aug 06 '15 at 14:27
  • 1
    Check out the test-only module in the Android Testing Blueprint sample: https://github.com/googlesamples/android-testing-templates/blob/master/AndroidTestingBlueprint/module-flavor1-androidTest-only/build.gradle – Jose Alcérreca Aug 07 '15 at 13:42

2 Answers2

22

I was also curious about separating app code and test code and i had hard time to figure it out. I look at the stack trace and found the DependencyManager (line 238) having a TODO to fix that in gradle.

1) You are right about the build flavors.You have to enter the correct variant

targetVariant '<flavor>Debug'

e.g.

targetVariant 'flavor1Debug'

2) You also need to change you targetProjectPath's module build.gradle. Add the following snippet:

android {

    // ...

    publishNonDefault true

    // ...

}

which publishes all build variants! It its disabled by default due to some limitations of gradle.

ben-efiz
  • 813
  • 9
  • 13
  • 'publishNotdefault true' was the answer I also got on the Android Developer Tools community - https://plus.google.com/+MariusBardan/posts/79MM5tPBFyp . It worked for me. – marius bardan Aug 06 '15 at 14:54
  • Is there any reason not to use your 'release' version as your targetVariant? – Alex Crist Aug 27 '15 at 18:25
  • 1
    @AlexCrist _debug_ is the default **non-minified** build type for testing because its takes less time to build and run (reducing test cycles). But of course its also good to test _release_ version especially when **minifying/obfuscating** or having any other configuration in the release block. So _debug_ for frequent testing and _release_ alongside. – ben-efiz Aug 28 '15 at 08:53
  • publishNonDefault true fixed my problem. I have no flavors for now so targetVariant 'debug' is working for me. – Ena Nov 05 '15 at 10:32
5

Here is a sample app that works https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint

You must use

buildToolsVersion = '23.0.0rc3'

And of course

publishNonDefault true
box
  • 4,450
  • 2
  • 38
  • 38