android - 无法从 gradle 命令行执行 testng.xml 文件
问题描述
我在 android studio 中使用 kotlin 创建了一个用于移动自动化的 gradle 项目,并在 build.gradle 中创建了任务当我从命令提示符执行测试时,例如:'gradle Test' 我的测试没有被执行(正在打印消息,上面提到了这个任务)。当我直接从 testng.xml 文件执行时,脚本会成功执行。
下面是 build.gradle 的示例代码
App -> build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.appium.automation"
minSdkVersion 21
targetSdkVersion 28`enter code here`
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'io.appium:java-client:7.0.0'
implementation 'org.assertj:assertj-core:3.12.2'
implementation 'org.testng:testng:6.14.3'
implementation 'org.junit.jupiter:junit-jupiter-api:5.5.0-M1'
implementation 'io.cucumber:cucumber-java8:4.3.1'
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'io.cucumber:cucumber-testng:4.3.1'
implementation 'io.cucumber:gherkin:5.1.0'
implementation 'com.aventstack:extentreports:4.0.9'
}
tasks.withType(Test) {
print("Hi")
useTestNG(){
println("Hi2")
suites '/app/testng.xml'
println("Hi3")
}
}
项目-> build.gradle
buildscript {
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
解决方案
要从命令行执行具体测试,您可以尝试:
./gradlew test --tests "com.MyTestCkass.myTest"
推荐阅读
- python-3.x - 创建一个只接受特定用户并使任何其他用户无效的问候程序
- r - 在 R 中计算夏普比率时的时间序列相关误差
- json - 使用 Ansible 创建 Jenkins 凭据时出错
- r - mutate 不适用于 na.spline/na.approx
- javascript - daterangepicker 在 Laravel 7 中没有使用引导程序折叠打开
- java - 在另一个类中包含一个 java 类(扩展)错误
- c#-4.0 - Sqlite自动递增表中的字段
- google-bigquery - 如何从 Apache Beam KafkaIO 中的 kafka 主题推断 avro 模式
- python - ThreadPoolExecutor 中的可调用没有阻塞
- vba - VBA - 将幻灯片名称输出到文本框 PowerPoint