4

我正在使用maven構建,運行和檢測我的Android應用程序。 Android測試框架有三個不同的測試範圍@SmallTest,@MediumTest@LargeTest,並且android-maven-plugin具有通過testTestSizetest/testSize參數選擇測試範圍的能力。該參數可以是​​之一,可以從相關範圍運行測試。android-maven-plugin,儀器測試和testSize

但是我能做什麼,如果我想同時運行中小型測試,不僅小或不僅中等?這個問題的任何解決方案存在?

回答

3

這是SDK的Android如何設計並認爲在目前的工作,根據InstrumentationTestRunner API doc

運行的所有小測試:亞行外殼上午儀器-w -e尺寸小com.android。富/ android.test.InstrumentationTestRunner

運行的所有媒體測試:亞行外殼上午儀器-w -e中等大小com.android.foo/android.test.InstrumentationTestRunner

運行的所有大測試:亞行外殼上午儀器-w -e尺寸大com.android.foo/android.test.InstrumentationTestRunner

即使你使用普通的ADB命令來運行你的測試,你有使用兩個過程分別運行中小型測試,一個接一個。 Android Maven插件只是adb命令的另一個包裝,因此無法通過android-maven-plugin配置AFAIK來更改默認行爲。


如果你仔細看InstrumentationTestRunner API doc,你會注意到,有一個有趣的命令用法:

篩選試運行與給定的註解測試:亞行外殼上午儀器-w - e註釋com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner

如果與其他選項一起使用,則生成的測試運行將包含兩個選項的聯合。例如「-e size large -e annotation com.android.foo.MyAnnotation」將只運行帶有LargeTest和「com.android.foo.MyAnnotation」註解的測試。

註釋配置添加作爲實驗API(標記爲@hide的更多細節,請查看this version history),並且尚未在am instrument options list被記錄在案。理論上你可以創建你自己的註解類(參見SmallTest.java作爲例子),將@MediumTest和@CustomizedTest一起標記出來,同時使用-e size和-e註解來實現你想要的:從兩個註釋同時運行聯合測試,全部一個命令。

不幸的是,android-maven-plugin不支持註釋配置,請參見plugin documentationlatest source code。可能的解決方法是使用exec-maven-plugin運行普通的adb shell am instrument命令。

希望這是有道理的。

0

從Maven的Android的使用測試規模,我已經創造了一個pom.xml的變量:

... 
<properties> 
    <config.build.testSize>medium</config.build.testSize> 
</properties> 
... 

,並在構建,到以下幾點:

<build> 
<pluginManagement> 
    <plugins> 
    <plugin> 
    <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
    <artifactId>android-maven-plugin</artifactId> 
    ... 
    <configuration> 
    <test> 
     <testSize>${config.build.testSize}</testSize> 
    </test> 
    </configuration> 
    ... 
    </plugin> 
    </plugins> 
</pluginManagement> 
</build> 

我認爲,你可以也可以通過給android.test.testSize參數來達到這個目的(如mvn install -Dandroid.test.testSize = medium)

如果我錯了,請在這個maven變量中更正,在doc中沒有找到。 BR, M.