The Eclipse unit test for Android Development Basics

Source: Internet
Author: User

Suppose you have implemented a compute percent function that requires testing, code:
public class Progressservice {public    Integer Getcurrentprogerss (double current, double max) {        Integer i= (int) (( Current/max);        return i;    }}

To unit test a specified feature, the following steps are detailed:


A test class

Writing a test class to perform our function, this class needs to inherit Androidtestcase.

Import Android.test.androidtestcase;import Android.util.log;import Com.example.service.progressservice;public Class Progressservicejunit extends Androidtestcase {    private final String tag= "main";        Public Progressservicejunit () {        //TODO auto-generated constructor stubs    } public        void Getcurrentprogersstest () {        progressservice progressservice=new progressservice ();        Integer Pro=progressservice.getcurrentprogerss (+);        LOG.I (TAG, pro.tostring ());}    }

Two JUnit supports the addition of JUnit support in Androidmanifest.xml and the development of a test project package.
1 <application> node before joining:
<uses-permission android:name= "Android.permission.RUN_INSTRUMENTATION"/> Add permission <instrumentationandroid: Name= "Android.test.InstrumentationTestRunner" fixed class capacity android:targetpackage= "Com.example.junittestdemo" > To test the package where the feature is located </instrumentation>

2 manifest.xml <application> added:
<application>...<uses-library android:name= "Android.test.runner"/> ...<application/>

Three runs the left mouse button on the test case method, run As→android JUnit test.

The Eclipse unit test for Android Development Basics

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.