
[英]Unit/Instrumentation tests Android Gradle. Instrumentation tests won't run
[英]Run android unit tests & instrumentation tests on Jenkins (Gradle)
我的 androidTest 文件夹中有一些单元和仪器测试。
我正在尝试在本地 Jenkins 上运行这些测试。
我已经成功地使用 Jenkins 配置了我的项目,并且我还为仪器测试创建了一个模拟器。
到目前为止,我看到的所有资源都只关注 ant 和早期版本的 Gradle。 当前版本中编写任务的语法略有变化,我对此感到困惑。
这是我的 build.gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "myPackageName"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
你可以像这样写一个 jenkis 脚本:
stage('Build & Install') {
//Build the apk and the test apk which will run the tests on the apk
sh 'chmod +x gradlew && ./gradlew --no-daemon --stacktrace clean :app:assembleDevDebug :app:assembleDevDebugAndroidTest'
}
stage('Tests') {
//Start all the existing tests in the test package
sh './gradlew --no-daemon --debug :app:connectedDevDebugAndroidTest'
}
这应该将 apk 和测试 apk 安装到设备中,并在安装时在测试 apk 中启动测试用例。
在这里,我给出了 DevDebug,因为我有一个名为 Dev 的风味常量,并且构建类型是 Debug。 如果你没有这些,你就不要使用它们。
在junkins中创建一个作业并(配置adb路径)添加此命令以构建步骤作为执行shell命令或作为windows bat cmd
$ adb shell am instrument -w com.xyz.abc.test/android.test.InstrumentationTestRunner
PS:-为了更好的自动化,使用robotium和spoon withjunins你可以自动化一切,你在git上提交一个提交,你会在你的邮件收件箱中得到测试结果,这太酷了。
编辑
使用勺子运行测试
添加这些命令以构建步骤
./gradlew assembleDebugAndroidTest
./gradlew assembleDebug
在spoon命令中正确指定debug-build.apk路径和test-unaligned.apk路径
java -jar C:\Users\Shivam\Downloads\spoon-runner-1.1.1-jar-with-dependencies.jar --apk C:\Users\Shivam\Downloads\SpoonAndRobotiumTest\app\build\outputs\
apk\app-debug.apk --testapk C:\Users\Shivam\Downloads\SpoonAndRobotiumTest\
app\build\outputs\apk\app-debug androidTest-unaligned.apk --sdk E:\sdk
首先,您必须在 Jenkins-CI 安装上安装 Gradle 插件。 您可以在http://yourhost/jenkins/pluginManager/搜索它
要继续集成它,您可以查看此演示文稿,特别是最新的幻灯片
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.