Android junit unit test, androidjunit

Source: Internet
Author: User

Android junit unit test, androidjunit

Classification of software testing
* Black box testing
* Test the logical business
* White box testing
* Test logic method

Based on test Granularity
* Method test: function test
* Unit test: unit test
* Integration test: integration test
* System test: system test

Based on test Brute Force
* Smoke test: smoke test
* Stress test: pressure test

Create an android project and create a Test. java file. Be sure to inherit AndroidTestCase by defining a class inheritance.

package com.wuyudong.juint.test;import com.wuyudong.juint.util.Utils;import android.test.AndroidTestCase;public class Test extends AndroidTestCase {        public void test() {        int res = Utils.add(3, 5);        assertEquals(8, res);    }}

Create the Toolkit file Utils. java

package com.wuyudong.juint.util;public class Utils {    public static int add(int a, int b) {        return a - b;    }}

Run the project and report the following error:

[06:21:13-unit test] unit test does not specify a android. test. InstrumentationTestRunner instrumentation or does not declare uses-library android. test. runner in its AndroidManifest. xml

Add the following code to AndroidManifest. xml:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.wuyudong.juint"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />        <instrumentation         android:name="android.test.InstrumentationTestRunner"        android:targetPackage="com.wuyudong.juint"        ></instrumentation>    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <uses-library             android:name="android.test.runner"/>        <activity            android:name="com.wuyudong.juint.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

Continue to run unit test. The following asserted exception occurs.

Double-click to jump

public class Test extends AndroidTestCase {        public void test() {        int res = Utils.add(3, 5);        assertEquals(8, res);    }}

 

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.