Android測試教程(8):測試Service

來源:互聯網
上載者:User

Android 測試架構也提供對Service測試的支援,基本類為ServiceTestCase,因為Service類通常假定和它是和Client是分開 使用的,因此你可以無需使用Instrumentation 來測試Service。

當你設計一個Service時,你應該考慮測試案例中如何檢查 Service的目前狀態,比如你在onCreate ,onStartCommand 中啟動一個Service,一般沒有一個全域變數來表示Service是否成功 ,你可能需要自己定義一個全域變數用於測試案例中。

ServiceTestCase 中提供getService() 可以取得當前被測試的 Service對象。

ServiceTestCase 為AndroidTestCase的子類,因此可以測試和Permission 相關的功能,並提供Mock的 Application 和Context 對象為測試Service提供了一個隔離的測試環境。

後面提供具體例子。

查看全套教程:http://www.bianceng.cn/OS/extra/201301/35252.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.