Android JUnit unit test procedure

Source: Internet
Author: User

//Step 1: Write the following sentence on the <activity> tag in the androidmainfest. xml fileCode
<Uses-library Android: Name = "android. Test. Runner"/>
// In androidmainfest. xml </Application>, enter the following code.ProgramPackage name
<Instrumentation Android: Name = "android. Test. instrumentationtestrunner" Android: targetpackage = "cn. itcast. Action" Android: Label = "tests for my app"/>
//Step 2: Compile the unit test code (select the method to be tested, right-click "Run as" -- "android JUnit test "):

Package CN. itcast. test;

Import JUnit. Framework. Assert;
Import CN. itcast. Service. personservice;
Import Android. Test. androidtestcase;

Public class personservicetest extends androidtestcase {

Private Static final string tag = "personservicetest ";

Public void testsave () throws throwable {
Personservice service = new personservice ();
Int B = service. Save (); // check whether the SAVE () method runs normally.
Assert. assertequals (78, B); // whether the expected value 78 is the same as the obtained value B

Log. I (TAG, B}; // Add a filter to logcat to view the printed information.
}

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.