Appium基礎學習之 | UiAutomator與Junit的關係

在《Appium基礎學習之 | UiAutomator使用》文章中大概介紹了UiAutomator的使用,把代碼打包成jar後推送到Android設備上並運行。然後在回顧一下《Appium基礎學習之 | Appium執行日誌流程分析》中講解到的,Appium其中一個重要的步驟就是把一個Bootstrap.jar推送到Android設備,這樣結合來說,應該更好的理解Appium與UiAutomator的關係了吧。Bootstrap.jar就如在使用UiAutomator中代碼通過ant打包後形成的jar,那麼在看看Appium的執行日誌,是如何運行Bootstrap.jar的。

如上圖,看shell命令,很清楚了,跟在使用UiAutomator中運行是一樣的。

接下來再繼續看看UiAutomator又是基於什麼運行的呢?在使用UiAutomator的時候,需要extends繼承UiAutomatorTestCase類,所以來看UiAutomator的UiAutomatorTestCase源碼:

package com.android.uiautomator.testrunner;

import android.content.Context;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.view.inputmethod.InputMethodInfo;

import com.android.internal.view.IInputMethodManager;
import com.android.uiautomator.core.UiDevice;

import junit.framework.TestCase;

import java.util.List;

/**
 * UI automation test should extend this class. This class provides access
 * to the following:
 * {@link UiDevice} instance
 * {@link Bundle} for command line parameters.
 * @since API Level 16
 */
public class UiAutomatorTestCase extends TestCase {

...........代碼省略

}

看上面代碼,發現UiAutomatorTestCase實際上是extends繼承TestCase,而從import來看,TestCase是屬於junit中的類,這裏就可以得到結論,所有的執行都是交給Junit來執行的。

其他關於UiAutomator源碼分析請參考:https://blog.csdn.net/zhubaitian/column/info/uiautomatorpriciple

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章