[Android Notes] ------ use of logcat and android junit

Source: Internet
Author: User

1. logcat: logcat can be used to record log information, which provides great convenience for debugging.1. Usage:(1) Use the command line adb logcat. Disadvantages: not intuitive.
(2) Use the graphical tool logcat provided by the adt plug-in.

2. debugging skills (for the graphical tool logcat)Android classifies log information into ERROR, WARN, INFO, DEBUG, and VERBOSE in different colors. We can easily tell different logs by color. In addition, you can use the buttons in the Red Circle in the figure to filter logs of different levels. There is a plus sign on the left side of the book. We can click the plus sign to add a custom filter. This is not enough. We should use the Log class in the code to print the required logs: Log. v (), Log. d (), Log. I (), Log. w (), Log. e () represents logs of different levels. The first parameter tag represents the tag. We generally use the class name as the tag name to facilitate filtering. The second parameter is the log information we need.

private static final String TAG = "MyActivity";Log.v(TAG, "index=" + i);

Ii. junit testing framework for Android:To use the junit framework in Android, you must inherit the AndroidTestCase class and specify the following information in the configuration file:
  
  
 
The instrumentation node can be placed under the root node manifest, and the user-library node must be placed under the application node. ADT provides us with an easy way to create a junit testing framework.1 . Create a test project.
The above code is automatically added to the project list file created using this method.
2. Select the project to be tested:
3. Compile the test method, right-click the corresponding test function name on the outline view, and run as Android junit test.Green bars indicate pass, and red bars indicate errors.
Note: To ensure the test accuracy, the test method should throw all exceptions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.