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); }}