在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ Android 測試教程(13):TestCase 示例
monkeyrunner 簡介
Android 測試教程(14):ActivityInstrumentationTestCase2 示例
ApplicationTestCase 示例
Android 測試教程(13):TestCase 示例
ActivityInstrumentationTestCase2 示例
測試 Activity
測試項目
Android 測試教程(12):ServiceTestCase 示例
測試相關(guān) API
Monkey 命令行工具
第一個測試項目 HelloWorldTest
測試 Content Provider
Android 測試教程(11):ActivityUnitTestCase 示例
測試基礎(chǔ)
AndroidTestCase 示例
測試 Service

Android 測試教程(13):TestCase 示例

Android 測試框架是基于 JUnit 的,因此對一些和平臺關(guān)系不大的類,可以直接使用 JUnit 中的 TestCase 來測試。

MorseCodeConverterTest 用來測試 MorseCodeConverter 類,MorseCodeConverter 的實現(xiàn)和 Android 平臺聯(lián)系不大,因此可以直接使用 TestCase 作為基類。

TestCase 由 Assert 類派生而來,Assert 提供了大量的 Assert方法,用來比較期望值和實際值。

本例代碼如下:


    public class MorseCodeConverterTest extends TestCase {

     @SmallTest
     public void testCharacterS() throws Exception {

     long[] expectedBeeps = {
     MorseCodeConverter.DOT,
     MorseCodeConverter.DOT,
     MorseCodeConverter.DOT,
     MorseCodeConverter.DOT,
     MorseCodeConverter.DOT};
     long[] beeps = MorseCodeConverter.pattern('s');

     assertArraysEqual(expectedBeeps, beeps);
     }

     private void assertArraysEqual(long[] expected, long[] actual) {
     assertEquals("Unexpected array length.",
     expected.length, actual.length);
     for (int i = 0; i < expected.length; i++) {
     long expectedLong = expected[i];
     long actualLong = actual[i];
     assertEquals("Unexpected long at index: " + i,
     expectedLong, actualLong);
     }
     }
    }

為一個基本的 JUnit Testcase 測試,使用 assertEquals 來測試期望值和實際值。

Tags: Android 測試