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

1万+

被折叠的 条评论
为什么被折叠?



