Android Basics-Unit Test framework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.