0

I've added a new build type called "debug_test" which has some BuildConfig differences made for testing. While I can run all the local unit tests when I switch to this build type I fail to run instrumented tests, actually I even fail to build instrumented tests when set to "debug_test" (various symbols are not there).

It looks like for my new build type the :app:generateDebugAndroidTestSources etc are not executed.

Debug runs:

Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]

Whereas debug_test runs:

Executing tasks: [:app:generateDebug_testSources, :app:mockableAndroidJar]

I struggle a little bit to grasp what I have to do mainly because I do not understand which operations are implicitly done for debug which I need to do for debug_test as well. Do I need to explicitly define task dependency to generateDebugAndroidTestSources in my app level build.gradle file?

Hints appreciated.

Samuel
  • 6,126
  • 35
  • 70

1 Answers1

0

Well this post here Android instrumented unit testing Cannot resolve symbol 'AndroidJUnit4' has an answer.

It looks like you can only have one instrumented test configuration. This document https://developer.android.com/studio/build/gradle-tips.html#change-the-test-build-type briefly mentions that but the implication is not clear.

Your android configuration in the app's gradle file looks like that:

android {
    ...
    defaultConfig {
        ...
    }

    testBuildType "debug" // This is not in the gradle file but this is implicitly set

    buildTypes {
        release {
            ...
        }

        debug {

        }

        debug_test {

            debuggable true
            signingConfig signingConfigs.debug
        }
    }
}

So to change on which configuration the instrumented tests are compiled the line testBuildType <my_config> must be added to the android configuration set.

It would be very nice if there would be a way to see all those implicit options.

Samuel
  • 6,126
  • 35
  • 70