Unit testing under Android

Source: Internet
Author: User

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) ;}}


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.