1, write a test class testcalcservice inherit Androidtestcase
2. Write test method and throw exception, write test code inside test method
3. Open Androidmanifest.xml To configure the test code inside
4, add under the manifest node
<instrumentation android:name= "Android.test.InstrumentationTestRunner"
Android:targetpackage= "Com.example.android003jnuit"/>
5, add under the application node
<uses-library android:name= "Android.test.runner"/>
The Add method in the class and method Calcservice.java to be tested
Package Com.example.android003jnuit.service;public class Calcservice{public int Add (int x, int y) {return x + y;}}
Testadd methods for testing classes and methods in Testcalcservice.java
Package Com.example.android003jnuit.test;import Android.test.androidtestcase;import Com.example.android003jnuit.service.calcservice;public class Testcalcservice extends Androidtestcase{public void Testadd () throws Exception{calcservice service = new Calcservice (); int result = Service.add (1, 4); Assertequals (5, result) ;}}