1. Java code Testcase.java inheriting Androidtestcase class
Package Com.test.casei; import android.test.androidtestcase;import android.util.Log; Public classTestCase extends Androidtestcase {Private StaticFinal String TAG ="TestCase"; @Overrideprotected voidsetUp () throws Exception {Super.setup (); LOG.I (TAG,"[SetUp]"); } Public voiddoworktest () {log.i (TAG,"[Doworktest]"); } @Overrideprotected voidTearDown () throws Exception {Super.teardown (); LOG.I (TAG,"[TearDown]"); }}
2. androidmanifest.xml file
<?xml version="1.0"encoding="Utf-8"? ><manifest xmlns:android="http://schemas.android.com/apk/res/android" Package="Com.test.casei"Android:versioncode="1"Android:versionname="1.0"> <uses-sdk android:minsdkversion="Ten"/> <Application Android:icon="@drawable/ic_launcher"Android:label="@string/app_name"> <uses-library android:name="Android.test.runner"/><!--Add android.test.runner--> </application> <!--to the test to add android.test.Instrumentat to the test Iontestrunner-<Instrumentation Android:name="Android.test.InstrumentationTestRunner"Android:targetpackage="Com.test.casei"Android:label="Test"/> </manifest>
3. Testcase.java Process
Setup ()------>doworktest ()---->teardown ()
Androidtestcase Test Usage