Is it possible to enter debug mode for android when running junit test?

≡放荡痞女 提交于 2019-12-05 15:28:40

问题


Usually i run a junit test using adb shell am instrument -w com.android.contacts.tests/android.test.InstrumentationTestRunner. And it actually works, it will run all my tests.

But when i make a breakpoints and wish to enter debug mode when running junit, it failed. The way i make breakpoints works when i debug normal android app.

So i searched web, and try something like adb shell am instrument -e debug true -e class com.android.contacts.AndroidUtilsTest -w com.android.contacts.tests/android.test.InstrumentationTestRunner, but still without luck. How do yours solve this problem? I not just want to debug the junit class, but also the code in normal project.


回答1:


I guess you are trying to debug your tests using Eclipse. If this is the case you can just select you test project, right click, Debug As... -> Android JUNit test and the execution will stop at the breakpoints you set in your tests or in your code.




回答2:


I found the answer just now. It will block when i start instrument since it is waiting for me to set a breakpoint. So After i make a breakpoint, then the junit start to run. So the sequence of debug a android junit project is :

  1. start instrument with debug set true.
  2. make a break point using command line or eclipse.
  3. the instrument will start to run automatically.



回答3:


To Debug Android JUnit test don't forget to put debuggable=true in the testable project.



来源:https://stackoverflow.com/questions/10942049/is-it-possible-to-enter-debug-mode-for-android-when-running-junit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!