????Instrumentation??android??????????
???????????? ???????[ 2015/9/10 16:02:53 ] ??????????????? ???????
????android???????????????instrumentation??instrumentation?????application instrumentation???????????????????????????????????????????????????android demo?????????????instrumentation????????????
????android demo
????MainActivity????????????
??????????????
????add??????????????????????ui??
????sub???????????????????????ui??
????changetextview?????????textview????????????????button?????????textview???????
????multip??????????????????????button???????????????????????????????????????ui??????
????SampleTest????????????
??????????????
???????У?
????sampleTest???InstrumentationTestCase?????????????????????
????public class sampleTest extends InstrumentationTestCase {
????private MainActivity sample = null;
??????????????/??????
????sampleTest???InstrumentationTestCase?????????getInstrumentation()???????Instrumentation???????Instrumentation??startActivitySync()??????????Activity?????Activity???????????intent??????????Activity
????Intent intent = new Intent();
????intent.setClassName("com.example.jc.instrumentsample"?? MainActivity.class.getName());
????intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
????sample = (MainActivity)getInstrumentation().startActivitySync(intent);
???????case???д??
?????????????????????test?key????
????????????????????????textview?????????????????????ui??????/??????????????????????????????PerFromClick(???runnable)?????к????е?btn2.performClick????????ui???????
????????????textview???????????assertEquals?????????????????
????public void testActivity(){
????Log.d("testActivity"??"testActivity");
????SystemClock.sleep(1500);
????getInstrumentation().runOnMainSync(new PerFromClick(btn));
????SystemClock.sleep(1500);
????assertEquals("hello andriod"??textView.getText().toString());
????}
????private class PerFromClick implements Runnable {
????Button btn2;
????public PerFromClick(Button button){
????btn2 = button;
????}
????@Override
????public void run() {
????btn2.performClick();
????}
????}
????AndroidManifest.xml?????
?????????????
????uses??library??????libraray????
????instrumentation?????????????????????????
????<uses-library android:name="android.test.runner" />
????<instrumentation android:targetPackage="com.example.jc.instrumentsample" android:name="android.test.InstrumentationTestRunner" />
??????????У?
????build????????????????????
????$ adb shell am instrument -w com.example.jc.instrumentsample/android.test.InstrumentationTestRunner
????com.example.jc.instrumentsample:????
????android.test.InstrumentationTestRunner??????????????????
???????н????
?????????????????????????????в??????????????????????
???????????????????4????????????3????????????????????м???log???????1????????????????????????
com.example.jc.instrumentsample.sampleTest:
Failure in testActivity
junit.framework.ComparisonFailure: expected:<[hello andrio]d> but was:<[this is my first androi]d>
at com.example.jc.instrumentsample.sampleTest.testActivity(sampleTest.java:84)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701??
Failure in testAdd:
junit.framework.AssertionFailedError: expected:<3> but was:<2>
at com.example.jc.instrumentsample.sampleTest.testAdd(sampleTest.java:102)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191??
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176??
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
.
Failure in testSub:
junit.framework.AssertionFailedError: expected:<1> but was:<-1>
at com.example.jc.instrumentsample.sampleTest.testSub(sampleTest.java:109)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Test results for InstrumentationTestRunner=.F.F..
Time: 6.338
FAILURES!!!
Tests run: 4?? Failures: 3?? Errors: 0
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11