Android eclipse中项目调试

来源:互联网 发布:c语言代码大全下载 编辑:程序博客网 时间:2024/05/19 00:17

一、logcat日志
 
 可在 Window->Show View->Other->Android->Log Cat 调出 Log Cat 界面常用的日志: 普通运行信息:i 错误信息:e 输出日志: Log.i(TAG, strings); 其中TAG 为日志标识符,一般用类名表示(方便查看此日志是某个类的输出),且常声明为静态常量.stirngs 为要输出的字符串.例:
 

Log.i(TAG, strings)

成功运行程序后,在输出日志Log Cat 视图中 即可查看到标识为 PhoneSMSTest 的信息

PS:可在Log cat 中创建一个过虑器,Log cat->create filter->Filter Name:随意.by tab name: 日志标识符,此处为 PhoneSMSTest

二、断点调试

1、设置断点:
在编码窗体的左边框上用鼠标双击,或者右键点击菜单,选择 Toggle Breakpoint菜单项。

这里写图片描述

2、在debug模式下运行程序进入调试状态:通过点击工具栏上的小虫按钮或者是在项目右键点击然后选择Debug As,Android Application菜单,启动程序的调试模式。
第一次运行调试模式eclipse会弹出如下确认窗口:

这里写图片描述

当程序运行到你的断点地方时就会停下,这时可以按照下面的功能键按需求进行调试:

 Run->step Into 逐语句 (或F5)
 
 Run->step Over 逐过程 (或F6,略过方法)

 Run->step Return 单步返回(或F7 , 逐语句进入方法后跳出.);

 Run->Run To Line 运行到光标处 (或 Ctrl + R)

 Run->Resume 断续运行到结束 (或F8)

查看断点时变量当前的值:右键点击对应的变量,在菜单上选择 watch 菜单项,变量的值就会出现在 expressions窗口中。

这里写图片描述

三、单元测试

在Eclipse中进行Android单元测试
1、在AndroidMenifest.xml配置文件中增加以下配置信息:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.cjm.android.test"      android:versionCode="1"      android:versionName="1.0">    <uses-sdk android:minSdkVersion="8" />    <!-- 访问HTTP服务所需的网络权限 -->    <uses-permission android:name="android.permission.INTERNET"/>    <application android:icon="@drawable/icon" android:label="@string/app_name">        ......        <!-- 单元测试需要用到的类库 -->        <uses-library android:name="android.test.runner"/>    </application>    <!-- 测试设备的主类和目标包 -->    <instrumentation         android:name="android.test.InstrumentationTestRunner"         android:targetPackage="com.cjm.android.test"/></manifest>

2、新建单元测试类,该类需要继承AndroidTestCase类。这个类本身是继承junit.framework.TestCase,并提供了getContext()方法,用于获取Android上下文环境

public class HttpTest extends AndroidTestCase {    String url = "http://10.173.78.30:7777/android_web/testServlet";    public void testGet() throws Exception {         String result = HttpClientUtils.handlerGet(url);        printResult(result);    }    public void testPost() throws Exception {         String result = HttpClientUtils.handlerPost(url);        printResult(result);    }}

3.测试

方法名–右键–Run As–>JUint Test即可进行调试了

0 0
原创粉丝点击