Debugging test case in Android Studio

Viewed 2571

How do you debug JUnit test case in Android studio? I placed a breakpoint and used "Debug Test case" but it just runs the code and the breakpoint is ignored.

Update: This is content of my build.gradle

apply plugin: 'com.android.application'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.****.mancala"
    minSdkVersion 18
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        debuggable true
    }
}
}

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.1.1'
}
2 Answers

Depending on the Run/Debug Configuration used, the same code with the same breakpoint will stop or not.

  • For a configuration with Test kind: All in package, the execution will not stop at breakpoint
  • For a configuration with Test kind: Class or Test kind: Method, the execution will stop at breakpoint
  • For a configuration with Test kind: All in directory with Directory: [myProjectPath]/app/src/test, the execution will stop at breakpoint
Related