問題描述
我有一個(gè) Android/Gradle 項(xiàng)目.每當(dāng)我想運(yùn)行測(cè)試時(shí),我都會(huì)運(yùn)行:
./gradlew connectedInstrumentTest
它在我的項(xiàng)目的測(cè)試文件夾下運(yùn)行我的所有測(cè)試.
我的測(cè)試文件夾有幾個(gè)自動(dòng)化測(cè)試以及非自動(dòng)化測(cè)試.我最感興趣的是在沒有慢速自動(dòng)化測(cè)試的情況下運(yùn)行快速的非自動(dòng)化測(cè)試.
有沒有辦法只運(yùn)行一組特定的測(cè)試,例如來自一個(gè)特定的類或類似的東西?我基本上是在詢問任何類型的分離,以便我可以在需要時(shí)選擇只運(yùn)行幾個(gè)測(cè)試.
<小時(shí)>這里創(chuàng)建了一個(gè)示例項(xiàng)目..p>
編輯 local.properties
以指向您的 Android SDK.
接下來,啟動(dòng)模擬器或?qū)⑹謾C(jī)連接到計(jì)算機(jī).然后您可以使用 ./gradlew connectedInstrumentTest --info
運(yùn)行測(cè)試.這會(huì)運(yùn)行所有測(cè)試.
我無法弄清楚的是如何只在一個(gè)類而不是所有測(cè)試中運(yùn)行測(cè)試.
Android Gradle Plugin 1.3.0 起
從 1.3.0 版開始,您可以(終于!)指定 Android Gradle 插件必須傳遞給 InstrumentationTestRunner
的參數(shù).
例如,如果您只想運(yùn)行帶有 @SmallTest
注釋的測(cè)試并忽略其他測(cè)試:
<代碼>android {//....默認(rèn)配置 {//....testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"testInstrumentationRunnerArgument "size", "small"}}
<小時(shí)>
舊的解決方法在插件 1.3.0 之前無法做到這一點(diǎn),但我發(fā)現(xiàn)了一些解決方法.基本上我已經(jīng)用 @SmallTest
注釋對(duì)快速測(cè)試進(jìn)行了注釋,并使用 InstrumentationTestRunner
的自定義子類我能夠只運(yùn)行它們而不是整個(gè)套件.
您可以在this gist中找到示例代碼.
I have an Android/Gradle project. Whenever I want to run tests, I run:
./gradlew connectedInstrumentTest
which runs all my tests under the test folder of my project.
My test folder has several automation tests as well as non-automation tests. I'm mostly interested in running the fast non-automation tests without the slow automation tests.
Is there a way to run just a specific set of tests, such as from one specific class or anything similar? I'm basically asking about any kind of separation so that I can choose to run just a few tests when I want to.
Created a sample project here.
Edit local.properties
to point at your Android SDK.
Next, start up an emulator or connect a phone to your computer. Then you can run tests using ./gradlew connectedInstrumentTest --info
. This runs all tests.
What I am unable to figure out is how to only run tests in, say, one class and not all tests.
Since Android Gradle Plugin 1.3.0
Starting from version 1.3.0 you can (finally!) specify the arguments the Android Gradle Plugin have to pass to the InstrumentationTestRunner
.
For example, if you want to run only the tests annotated with @SmallTest
and ignore the others:
android {
//....
defaultConfig {
//....
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "size", "small"
}
}
Old workaround
Prior to plugin 1.3.0 is not possible to do that but I've found a little workaound. Basically I've annotated with the @SmallTest
annotation the fast tests and using a custom subclass of the InstrumentationTestRunner
I'm able to run just them and not the whole suite.
You can found the example code in this gist.
這篇關(guān)于有沒有辦法只在 Android Gradle 項(xiàng)目中運(yùn)行一組特定的儀器測(cè)試?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!