How to Debug Code with Android Studio



Being Tester we are used to reporting bugs and we know that developer debug the code to find out the line of code causing the bug. But now you are the one coding the test cases and you are responsible for solving any bug in your testing framework.


Android Studio provides some shortcut keys for debugging. In this post, we will use our HelloWord Espresso test Case Example and We will run our test Case In Debug mode and we will debug our code line by line.


It is always good practice to use Debug Mode for root tracing the bug as it allows you to run your code line by line by setting a debug point. Debug point is the nothing but marking the line of code from which you wish to start debugging. This speeds up your work and efficiency.

  • In your Android Studio project copy the below test case.
  •  
  • Now we will set a debug pointer. Suppose we are confident that our test of code is working fine except our test and we wish to debug the test case then we will place our debug pointer at the first line inside our test case. For this click on the left side space in front of the selected line and the pointer is set as shown the below screenshot(Red Dot represents the debug point).

  • Now we need to run our test case in Debug mode. Select the class name -> right click -> Debug as “MyActivityTest”. Make sure that the Android device is attached to your computer with USB debugging ON.

    Debug

  • As soon as your code runs till the debug point. You will see a debug console on your bottom left side and the code stops running at the debug point. Now the control is in your hands to run the code line by line.

  • The button highlighted in below screenshot allows you to run the rest of the code. When you click on it rest of the code runs automatically.

  • The button highlighted in below screenshot allows you to run the code step by step. Each time you click the button the line highlighted in the code gets executed.

  • You can also observe what is getting stored in your variables by opening checking variable window –

This will help you debug your test cases and write a efficient and bug free code.






Leave a Reply

bodrum escort - eskişehir esc - mersin escort - mersin escort bayan - mersin esc