1. Define a class to inherit androidtestcase, define a method in a class, select a method, right-click, runas-->android Junit test to test the way the method runs, without complex operations such as interface jumps.
Public classTestextendsAndroidtestcase { Public voidTest () {System.out.println (The "test method call"); } Public voidTest () {intresult = Add (3, 5); //Assertion: Check that the actual structure is consistent with the expected structureAssertequals (8, result);//This will cause the execution result to fail } Public voidtest2 () {inti = 4/0;//throws an exception, execution result fails } Public intAddintIintj) { returnI-j;//something went wrong here. } }
2. Need to specify the instruction set and the class library used in the Androidmanifest.xml manifest file
Specifies that the label for the instruction set is a child node of the root node manifest , targetpackage specifies the package name of the app you want to test
<android:name= "Android.test.InstrumentationTestRunner" android: Targetpackage= "Com.itheima.mytest"></instrumentation>
Specifies that the class library label used is a child node of the application label
<android:name= "Android.test.runner"/>
Android Basics-Unit Test framework