1.清单文件中的配置
<uses-library android:name="android.test.runner" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.jason.timetest" android:label="Tests for My App" />
2.测试类的继承(此处是获取系统12/24小时制的时间的测试代码)
package com.jason.timetest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.test.AndroidTestCase;
import android.text.format.DateFormat;
import android.util.Log;
public class TestTime extends AndroidTestCase {
private static final String TAG = "TestTime";
public void testSomething() throws Throwable {
//通过DateFormat获取系统的时间
String currentTime=DateFormat.format("yyyy-MM-dd hh-mm-ss", new Date()).toString();
Log.i(TAG, "通过DateFormat获取的时间:\n"+currentTime);
//通过SimpleDateFormat获取24小时制时间
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.getDefault());
Log.i(TAG, "\n"+"通过SimpleDateFormat获取24小时制时间:\n"+sdf.format(new Date()));
//通过SimpleDateFormat获取12小时制时间
sdf=new SimpleDateFormat("yyyy-MM-dd hh-mm-ss", Locale.getDefault());
Log.i(TAG,"\n" + "通过SimpleDateFormat获取12小时制时间:\n"
+ sdf.format(new Date()));
}
}