Unit test framework junit, unit test junit
# Unit test junit
* Define a class that inherits AndroidTestCase. Define a method in the class to test this method.
* When specifying the command set, targetPackage specifies the package name of the application you want to test.
<Instrumentation
Android: name = "android. test. InstrumentationTestRunner"
Android: targetPackage = "com. itheima. junit"
> </Instrumentation>
* Define the class library used
<Uses-library android: name = "android. test. runner"> </uses-library>
* The role of assertion to check whether the running result is consistent with the expectation
* If an application exception occurs, it is thrown to the test framework.
# Case:
Import com. itheima. junit. utils. Utils;
Import android. test. AndroidTestCase;
Public class TestCase extends AndroidTestCase {
Public void test (){
Int result = Utils. add (3, 5 );
// Assert asserted: used to check whether the actual value is consistent with the expected value
AssertEquals (8, result );
}
Public void test2 (){
Utils. chuyi (2, 1 );
}
}