The Android.jar is self-contained in the JUnit unit test class, so as long as the configuration of the relevant unit test can be used in large project development when testing their corresponding modules very good.
Build an Android project that contains a class add that completes the addition operation and builds the appropriate junit to perform the relevant tests.
First, add the application inside the androidmanifest:
<uses-library android:name= "Android.test.runner"/>
A library used for well-known needs;
Next, add it outside the application:
<instrumentation android:name= "Android.test.InstrumentationTestRunner" android:targetpackage= " Com.example.testjniandroid "android:label=" Tests for My App "/>
The targetpackage here needs to indicate the package name for the project.
In run as, you need to configure the running mode, select the Android JUnit Test, and then configure it accordingly.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/59/5B/wKiom1TQl8qDTih0AANU6JKKpMI767.jpg "title=" Configure run. png "alt=" wkiom1tql8qdtih0aanu6jkkpmi767.jpg "/>
Classes that need to be tested:
public class Add{int A,b;public Add (int a,int b) {this.a=a;this.b=b;} public int GetResult () {return a+b;}}
Write the class code for the test:
Import Junit.framework.testcase;public class Addtest extends TestCase {public void Testadd () {//fail ("not yet implemented "); Add x=new Add (1, 2); Assertequals (X.A, 1); Assertequals (x.b, 2);} public void Testgetresult () {//fail ("not yet implemented"); Add x=new Add (9,7); int Result=x.getresult (); SYSTEM.OUT.PRINTLN ("Result:" +result); Assertequals (result, 16);}}
The code is very simple, mainly to detect the results of the implementation is correct. Next is the run as Android JUnit Test to see the results:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/59/5B/wKiom1TQmW6DOkw8AAEYolcquqk528.jpg "title=" Run the result. png "alt=" wkiom1tqmw6dokw8aaeyolcquqk528.jpg "/>
The above use of unit tests is very simple and is documented for later review. More detailed unit testing scenarios will be accumulated later.
This article from "thedevilking" blog, declined reprint!
Using unit tests under Android