[英]How to run tests filtered with tags with cucumber-jvm and gradle?
我現在使用黃瓜已經有一段時間了,現在我想將測試套件的使用情況從maven遷移到gradle。
我設法准備項目,包括基本用法,運行測試,結果等。我遺漏的最后一塊是只能運行在特定標簽上過濾的測試。 運行驗收測試是通過產品風格完成的:
productFlavors {
uats {
testInstrumentationRunner "com.paddy.cuespton.cuespton.test.Instrumentation"
}
full {
applicationId "com.paddy.app.cuespton"
versionName "1.0"
}
}
這使我能夠使用任務運行測試:
./gradlew connectedAndroidTestUatsDebug
是否可以將param with tag添加到此任務以僅運行特定測試?
我嘗試使用https://github.com/samueltbrown/gradle-cucumber-plugin/插件,理論上應解決此問題,但由於語言不兼容,我無法使用Android運行。
這是我工作的回購, https://github.com/paddyzab/espresso-cucumber-sandbox 。
感謝幫助!
沒有嘗試這個黃瓜插件,但假設我們有類似的設置,你可以做以下( 樣本回購 ):
1)為uats風格定義相應的buildConfigField:
Uats {
testInstrumentationRunner "com.quandoo.gradletestpoc.test.Instrumentation"
// passing instrumentation parameters
buildConfigField "String", "TAGS", "\"${getTagsProperty()}\""
}
2)定義getTagsProperty()方法:
def getTagsProperty() {
return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
}
3)處理自定義檢測類的onCreate()方法中的傳遞標記:
private static final String TAGS_KEY = "tags";
......
@Override
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
// Reading runner params
String tags = BuildConfig.TAGS;
if (!tags.isEmpty()) {
bundle.putString(TAGS_KEY, tags);
}
instrumentationCore.create(bundle);
start();
}
4)跑
./gradlew connectedAndroidTestUatsDebug -Ptags="@bar"
請享用!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.