Android兼容性測試工具:Spoon
android分布式測試工具。
簡介
android眾多的版本和機型給android app測試工作帶來不小的挑戰。Spoon通過將case分布式地執行、將執行結果更友好地展示出來,從而簡化android app的測試工作。
Spoon沒有開發新的測試框架,而是讓已經存在的測試框架更有效。現在的測試框架,一般都是通過測試apk來驅動被測apk,Spoon可以讓這些case在多臺設備上同時運行。一旦測試結束,Spoon就是生成一份html報表,來展示每臺設備上的執行結果。
Spoon會檢測到adb devices
命令中顯示的全部設備,并在這些設備上執行case。所以我們在使用spoon時,可以插入不同的手機、平板、或者不同配置的模擬器。
插入的設備越多、越雜,那么最終的測試結果展示的信息就越多。
截圖
除了單純地跑case,Spoon還可以在case執行中,進行截圖,并在結果中進行展示。在最后的結果中,我們可以看到不同設備跑一個case時的截圖,來測試app的兼容性。
使用Spoon的截圖功能,必須在被測app中引入spoon-client
jar包,在我們的測試代碼中調用screenshot
方法進行截圖,這些截圖會被打上標簽。
Spoon.screenshot(activity, "initial_state");
//這里編寫登陸代碼
Spoon.screenshot(activity, "after_login");
代碼里指定的tag用來命名截圖,以便在測試兼容性的時候進行不同設備間的橫向比較。
我們也可以連貫地瀏覽每臺設備上的截圖,來查看運行過程。
下載
下載最新的runner jar包或者最新的client jar包,或者通過maven來獲取:
<dependency>
<groupId>com.squareup.spoon</groupId>
<artifactId>spoon-client</artifactId>
<version>(insert latest version)</version>
</dependency>
執行
Spoon既可以單獨運行,又可以集成到maven里,作為maven命令的一部分來執行。
單獨運行,需要被測apk包和測試apk包,執行下面的命令即可:
java -jar spoon-runner-1.0.0-jar-with-dependencies.jar \
--apk example-app.apk \
--test-apk example-tests.apk
執行結果,默認會放在當前目錄的spoon-output文件夾下。當然還有一些其他的參數,具體如下:
Options:
--apk 被測apk
--fail-on-failure Non-zero exit code on failure
--output 結果路徑
--sdk android sdk路徑
--test-apk 測試apk
--title Execution title
--class-name Test class name to run (fully-qualified)
--method-name Test method name to run (must also use --class-name)
--no-animations Disable animated gif generation
--size Only run test methods annotated by testSize (small, medium, large)
--adb-timeout Set maximum execution time per test in seconds (10min default)
如果使用maven來執行,有個maven插件可以用。在pom.xml
中加入下面代碼:
<plugin>
<groupId>com.squareup.spoon</groupId>
<artifactId>spoon-maven-plugin</artifactId>
<version>(insert latest version)</version>
</plugin>
這個插件會自動尋找被測試的apk包。這個apk包通常還會以jar包的形式在dependency中進行聲明。
<dependency>
<groupId>com.example</groupId>
<artifactId>example-app</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-app</artifactId>
<version>${project.version}</version>
<type>apk</type>
<scope>provided</scope>
</dependency>
配置了上面的插件,我們可以通過mvn spoon:run
來執行。執行結果放在target/spoon-output/
文件夾。如果想手動指定test class,可以在命令中添加參數-Dspoon.test.class=fully.qualified.ClassName
。如果想手動指定test method,可以在命令中再添加參數-Dspoon.test.method=testAllTheThings
。