Android: Using unit Tests

Source: Internet
Author: User

First, join the configuration item:

1. In application, add the reference test class library code to the activity item:

<uses-libraryAndroid:name= "Android.test.runner" />

2. Add the "Test entry" code to the application entry:

<InstrumentationAndroid:name= "Android.test.InstrumentationTestRunner"Android:targetpackage= "Com.juniux.junittest"Android:label= "Test My App" />
<!--The Android:label property can be ignored -

Second, the editing test class:

Note: This class inherits the Androidtestcase class and is recommended to be named: "Class name to test" +test; test method Name: test+ "method name to test" and throws exception.

PackageCom.juniux.test;
ImportJunit.framework.Assert;
ImportCom.juniux.services.PersonService;
ImportAndroid.test.AndroidTestCase;
PublicclassPersonservicetestextendsAndroidtestcase {
PublicvoidTestsave ()throwsException {
Personservice Service =NewPersonservice ();
Service. Save (NULL);
}
PublicvoidTestadd ()throwsException
{
Personservice Service =NewPersonservice ();
intresult = Service. ADD (1, 2);
Assert.assertequals (3, result);
}
}

Three: Enable testing

Right-click the method you want to test in the outline list and select the Android JUnit Test start test, RunAs.

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.