Android junit Unit Test

Source: Internet
Author: User

Classification of software Testing
* Black box test
* Test Logic Business
* White Box test
* Test Logic method

According to the test grain size
* Method Test: Function test
* Unit tested: Unit test
* Integration testing: Integration test
* System tests: Systems Test

According to the level of testing violence
* Smoke test: Smoke test
* Stress test: Pressure test

Create a new Android project, create a new Test.java file, and note that defining a class inheritance must be inherited androidtestcase

 Package com.wuyudong.juint.test; Import com.wuyudong.juint.util.Utils; Import android.test.AndroidTestCase;  Public class extends androidtestcase {        publicvoid  Test () {        int res = Utils.add (3, 5);        Assertequals (8, res);}    }

New Toolkit File Utils.java

 Package Com.wuyudong.juint.util;  Public class Utils {    publicstaticint Add (intint  b) {         return A- b;    }}

Run the project, error:

[2016-05-30 06:21:13-Unit Test] Unit test does not specify a android.test.InstrumentationTestRunner instrumentation or does not de Clare Uses-library Android.test.runner in its androidmanifest.xml

Add the following code to the Androidmanifest.xml:

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.wuyudong.juint"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" />       <instrumentation  android:name= "Android.test.InstrumentationTestRunner" 
      android:targetpackage= "Com.wuyudong.juint"></instrumentation
      >               <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >     <uses-library  android:name= "Android.test.runner"/>             <ActivityAndroid:name= "Com.wuyudong.juint.MainActivity"Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>

The following assertion exception occurs when you continue to run the unit tests test

Double-click Jump to

 Public class extends androidtestcase {        publicvoid  Test () {        int res = Utils.add (3, 5 );        assertequals (8, res);}    }

Android junit Unit Test

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.