問題描述
我有一個 Android/Gradle 項目.每當我想運行測試時,我都會運行:
./gradlew connectedInstrumentTest
它在我的項目的測試文件夾下運行我的所有測試.
我的測試文件夾有幾個自動化測試以及非自動化測試.我最感興趣的是在沒有慢速自動化測試的情況下運行快速的非自動化測試.
有沒有辦法只運行一組特定的測試,例如來自一個特定的類或類似的東西?我基本上是在詢問任何類型的分離,以便我可以在需要時選擇只運行幾個測試.
<小時>這里創建了一個示例項目..p>
編輯 local.properties
以指向您的 Android SDK.
接下來,啟動模擬器或將手機連接到計算機.然后您可以使用 ./gradlew connectedInstrumentTest --info
運行測試.這會運行所有測試.
我無法弄清楚的是如何只在一個類而不是所有測試中運行測試.
Android Gradle Plugin 1.3.0 起
從 1.3.0 版開始,您可以(終于!)指定 Android Gradle 插件必須傳遞給 InstrumentationTestRunner
的參數.
例如,如果您只想運行帶有 @SmallTest
注釋的測試并忽略其他測試:
<代碼>android {//....默認配置 {//....testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"testInstrumentationRunnerArgument "size", "small"}}
<小時>
舊的解決方法在插件 1.3.0 之前無法做到這一點,但我發現了一些解決方法.基本上我已經用 @SmallTest
注釋對快速測試進行了注釋,并使用 InstrumentationTestRunner
的自定義子類我能夠只運行它們而不是整個套件.
您可以在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.
這篇關于有沒有辦法只在 Android Gradle 項目中運行一組特定的儀器測試?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!