我已经在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
}
答案 0 :(得分:0)
我想问题出在测试选项上,请尝试将此代码插入到应用级别的 build.gradle 中。
android {
testOptions {
unitTests.includeAndroidResources = true
unitTests.all {
useJUnitPlatform()
reports {
junitXml.enabled = true
html.enabled = false
}
testLogging {
events "passed", "skipped", "failed"
// to run JUnit 3/4 tests:
testImplementation("junit:junit:4.12")
testRuntime("org.junit.vintage:junit-vintage-engine:5.7.0")
}
}
}
}
此问题已在以下位置提及:https://github.com/kotest/kotest/issues/622