Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug when running Robolectric tests in Android Studio?

I need to run debug while my tests execution in Android Studio + Robolectric. Each time I try to run them by selecting debug for the test task from Gradle tasks I get the error message:

Error running package_name:app_name [test]: Unable to open debugger port : java.net.SocketException "Socket closed"

Any ideas?

like image 356
Eugene Avatar asked Jan 17 '14 11:01

Eugene


People also ask

Is your Robolectric test running on the JVM or on an Android emulator What is the advantage of this?

The major benefit of Robolectric is speed. Unit tests with Robolectric do not require a running emulator or device to run the tests and are thus much much faster.

How do I run test cases on Android?

To run all tests in a class or a specific method, open the test file in the Code Editor and do either of the following: Press the Run test icon in the gutter. Right-click on the test class or method and click Run . Select the test class or method and use shortcut Control+Shift+R .

What is the significance of Robolectric?

Robolectric provides a JVM compile version of the android. jar file. Robolectric handles views, resource loading, and many other things that are implemented in the Android native. This enables you to run your Android tests in your development environment, without requiring any other setup to run the test.


2 Answers

I found the reason of the error. To make it run you need to uncheck the "Use in-process build" option in Compiler -> Gradle settings of Android Studio.

enter image description here

like image 106
Eugene Avatar answered Oct 18 '22 01:10

Eugene


I was getting this error on linux, and the problem was that the another previous process has taken the port and hung. So, the solution is a netstat to locate the process blocking the port, then kill this process, or you can restart the machine.

like image 22
Rogelio Triviño Avatar answered Oct 18 '22 03:10

Rogelio Triviño