android自动化框架简要剖析(一):运行原理+基本框架
android自動化測試原理:
1、將測試apk和被測試apk,運行在一個進程中;通過instrumentation進行線程間的通信
2、通過android.test.AndroidTestCase及其子類,控制android系統對象
3、通過android.test.InstrumentationTestCase 及其子類,測試Activity
被測試程序的manifest文件中要指定被測試程序,如下:
<instrumentation
???????? android:name="android.test.InstrumentationTestRunner"?
???????? android:targetPackage="cn.mama.activity" />
?
4、當你運行一個測試程序時,首先會運行一個系統工具叫做Activity Manager。
Activity? Manager使用Instrumentation框架來啟動和控制TestRunner,
這個TestRunner反過來又使用Intrumentation來關閉任何主程序的實例,
Activity? Manager加載并啟動你的測試程序,殺死主程序的任何實例,
然后在測試程序的同一個進程里加載主程序,然后傳遞測試程序的第一個測試用例。
這個時 候,TestRunner會接管這些測試用例,運行里面的每個測試方法,直到所有的方法運行結束。
這就能確保測試程序與主程序間的直接交互。
?
1、Instrumentation測試程序和被測試程序通信核心,起測試驅動作用。目前的robotium、athran、Selendroid...都是二次封裝它,作為測試api用。
就像Selenium 2 的webdriver一樣,測試架構和代碼風格很類似
這里只列出主類列表,具體解釋看第二篇
java.lang.Objectjava.lang.Object
? android.app.Instrumentation
? android.app.Instrumentation
? android.test.InstrumentationTestRunner
?
2、junit.framework.TestCase測試框架,用來管理測試用例 和 用例集
java.lang.Object
? junit.framework.Assert
? junit.framework.TestCase
? android.test.InstrumentationTestCase
? android.test.ActivityTestCase
? android.test.ActivityInstrumentationTestCase2<T extends android.app.Activity>
?
java.lang.Object
? junit.framework.Assert
? junit.framework.TestCase
? android.test.AndroidTestCase
??android.test.PerformanceTestCase ? (這是Interface)
Known Direct Subclasses:
AndroidTestCase,
InstrumentationTestCase,
TestSuiteBuilder.FailedToCreateTests
Known Indirect Subclasses
ActivityInstrumentationTestCase<T extends Activity>,
ActivityInstrumentationTestCase2<T extends Activity>,
ActivityTestCase,
ActivityUnitTestCase<T extends Activity>,
ApplicationTestCase<T extends Application>,
LoaderTestCase,
ProviderTestCase<T extends ContentProvider>,
ProviderTestCase2<T extends ContentProvider>,
ServiceTestCase<T extends Service>,
SingleLaunchActivityTestCase<T extends Activity>,
SyncBaseInstrumentation
轉載于:https://www.cnblogs.com/zhitang2009/p/3423068.html
總結
以上是生活随笔為你收集整理的android自动化框架简要剖析(一):运行原理+基本框架的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做梦梦到在游泳池里游泳是什么意思
- 下一篇: 梦到和一个人结婚代表什么