JUnit Test in Android

Source: Internet
Author: User

  in the in Development JUnit Testing makes it easy to find and handle problems as early as possible, and it's very easy to use, just import junit test-related jar packages and create test classes to test your business capabilities without having to test your code to add an output statement to your code. It should be noted that the test method written can only be public void and no parameters, and in the test method will do whatever it takes.

@Test  Public void Testadd () {    new  Demo ();    System.out.println (D.add);}

Testing in the Android environment does not seem to be convenient, and you need to configure the test in your app project configuration to write the test class. Fortunately, Google provides an ADT integration environment for everyone, and this problem is not a problem.
Next, take a look at an Android project to do the JUnit test configuration steps:
1. Find the <application></application> section in the project's Androidmanifest.xml file toadd:

<android:name= "Android.test.runner"/>

2, found in the project Androidmanifest.xml file <manifest></ Manifest > section, where to add:

< Intent-filter >   <  android:name= "Android.intent.action.MAIN"/>   <   android:name= "Android.intent.category.LAUNCHER"/></ Intent-filter >        

3, create a test class, inherit Androidtestcase, in which to write test methods. Such as:

     Public void throws Exception {        new  personservice ();        Ps.getfirstname ();    }      Public void throws Exception {        new  personservice ();        Assert.assertequals (2, Ps.calc ());    }

4. Finally, the Android JUnit test,junit window will display a red or green bar, and you'll see some information in the console, such as:

[2014-05-26 17:04:47-slidedemo]------------------------------[2014-05-26 17:04:47-slidedemo] Android launch! [2014-05-26 17:04:47-slidedemo] adb is running normally. [2014-05-26 17:04:47-slidedemo] Performing Android.test.InstrumentationTestRunner JUnit launch[2014-05-26 17:04:47-slidedemo] Automatic Target Mode: Using existing emulator ' emulator-5554 ' running compatible AVD ' XT531 ' [2014-05-26 17:04:47-slidedemo] uploading Slidedem o.apk onto device ' emulator-5554 ' [2014-05-26 17:04:48-slidedemo] Installing slidedemo.apk ... [2014-05-26 17:04:49-slidedemo] success! [2014-05-26 17:04:49-slidedemo] Launching instrumentation Android.test.InstrumentationTestRunner on emulator-5554[2014-05-26 17:04:50-slidedemo] Sending test information to eclipse[2014-05-26 17:04:50-slidedemo] test run finished

Related Article

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.