Android学习笔记(二)

本文介绍了一个简单的Android应用程序如何使用内置的日志记录功能,并通过一个具体的单元测试案例展示了如何进行基本的功能验证。

日志输入

LogActivity

package org.wp.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

/**
 * 
 * 调整日志输出的级别 
 * Eclipse ==> Window ==> Preferences ==> Android ==> DDMS ==> Logging Level
 * 日志输入 
 * Eclipse ==> Window ==> Show View ==> Other ==> Android ==> LogCat
 * 
 * @author wp
 * 
 */

public class LogActivity extends Activity {
	private static final String TAG = "LogActivity"; // 快捷键ctrl+shift+x

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Log.i(TAG, "LogActivity Created");
	}
}

 

单元测试(Debug)

LogTest

package org.wp.activity;

import android.test.AndroidTestCase;
import android.util.Log;

/**
 * JunitRun ==> LogTest(实例化) ==> testSave() 
 * Debug 
 * Step Into F5 
 * Step Over F6 
 * Run to Line Ctrl + R 
 * Step Return F7
 * 
 * @author wp
 * 
 */

public class LogTest extends AndroidTestCase {

	private static final String TAG = "LogTest";

	public void testSave() throws Exception {
		int i = 1 + 1;
		String result = practice(i);
		Log.i(TAG, "result=" + i);
		Log.i(TAG, "result=" + result);
	}

	private String practice(int i) {
		int a = i;
		int b = 100;
		int c = a + b;
		String out = "wp";
		String result = out + c;
		return result;
	}
}

 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
	package="org.wp.activity" android:versionCode="1" android:versionName="1.0">
	<application android:icon="@drawable/icon" android:label="@string/app_name">
		<uses-library android:name="android.test.runner" />
		<activity android:name=".LogActivity" android:label="@string/app_name">
			<intent-filter>
				<action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
		</activity>
	</application>
	<uses-sdk android:minSdkVersion="7" />
	<instrumentation android:name="android.test.InstrumentationTestRunner"
		android:targetPackage="org.wp.activity" android:label="Tests for My App" />
</manifest> 

 

 

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值