Dienstag, 25. Februar 2014

Attaching debugger when running Robolectric tests from Android Studio

The Gradle View (View → Tool Windows → Gradle) in Android Studio allows you to easily run your unit tests from within Android Studio. From the tree of tasks for your project, just select the task test and run it.
It's also possible to attach the debugger to that process executing your Robolectric tests by simply choosing Debug instead of Run. However, you might face this error:
Error running android-app:appname [test]: Unable to open debugger port : java.net.SocketException "Socket closed" 
In order for the debugger to attach you need to uncheck "Use in-process build" in the settings menu for Android Studio under Compiler → Gradle.