我正在使用 64 位 Windows 7 上的 Android Studio。我是 Android Studio(或任何 Intelij IDE)的新手。
我下载并安装了 Ruby 1.9.3、Ruby DevKit 和 calabash-android,我可以使用命令行(calabash-android run)在我的 Android 应用程序上成功运行 Cucumber 测试
我还设法为 Android Studio 安装了 Cucumber 插件,这样我的功能文件就可以从自动完成等功能中受益。
我有以下问题:
我可以安装一个 Ruby 插件(RubyMine?)以便为我的测试编写步骤定义吗?如果是这样,我听说人们可以调试 Cucumber 测试:这可以在 Android Studio for Android 应用程序中实现吗?
我可以从 Android Studio 为 Android 应用启动葫芦测试吗?如果是这样,我会怎么做?
我可以在 Android 应用程序的 Gradle 版本中使用 calabash 集成(自动)测试吗?如果是这样,我会怎么做?
谢谢!
更新:
我附加了一个自定义 gradle Plugin<Project>
(请参阅下面我编写的凹槽代码,以对运行 calabash-android 测试提供基本支持。
这些手动步骤仍然是必要的:
- 安装 Ruby 1.9.x 及其 Devkit,安装 calabash-android gem 等。
- 使用 android gradle 插件(手动或自动)构建适当的(风格的)APK
在应用程序中build.gradle
,添加apply plugin: 'calabash'
现在可以工作,它允许构建运行功能文件作为葫芦测试。
它检查可用的产品风味(构建风味)并添加适当的葫芦相关任务(例如calabashDebug
或calabashFlavor1Release
等)。
下面是实现我的 'calabash' 插件的 groovy 文件(目前仅适用于 Windows):
package com.mediaarc.gradle.plugins
import org.gradle.api.*
import org.gradle.api.plugins.*
import org.gradle.api.tasks.*
class CalabashPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create("calabash", CalabashPluginExtension)
if (!project.android) {
throw new IllegalStateException("Android plugin is not configured.")
}
project.android.applicationVariants.each { variant ->
final def buildName = variant.name
final def buildVar = variant.baseName
final def packageApp = variant.packageApplication;
project.task("doPrepare${buildName}") << {
project.calabash.init(project, buildVar)
def apkFile = packageApp.outputFile
project.calabash.writeCommandFile(apkFile)
}
project.task("doClean${buildName}") << {
project.calabash.init(project, buildVar)
project.calabash.clean()
}
project.task("calabash${buildName}", type: Exec, dependsOn: [ project["assemble${buildName}"], project["doPrepare${buildName}"] ]) {
println project["assemble${buildName}"]
project.calabash.init(project, buildVar)
configureTask(project[name], buildName)
project.calabash.execute(project[name])
}
project.task("cleanCalabash${buildName}", dependsOn: project["doClean${buildName}"]) {
project.calabash.init(project, buildVar)
configureClean(project[name], buildName)
}
}
}
private def configureTask(def task, def buildVariant) {
task.group = JavaBasePlugin.VERIFICATION_GROUP
task.description = "Runs calabash tests for Build '${buildVariant}'"
}
private def configureClean(def task, def buildVariant) {
task.group = BasePlugin.BUILD_GROUP
task.description = "Deletes the calabash tests results for Build '${buildVariant}'"
}
}
class CalabashPluginExtension {
def root = 'src/calabash'
def resultFile = "calabash-results.html"
//protected def hash = new Object()
protected File outputFile
protected File workingDir
protected File tmpFile
protected init(Project project, def buildVariant) {
if (!buildVariant) {
buildVariant = "debug"
}
File rootFile = project.file(root)
outputFile = new File(project.file("build/reports/calabash/${buildVariant}"), resultFile)
workingDir = rootFile
}
protected writeCommandFile(def apkFile) {
if (!workingDir.exists()) {
throw new IllegalStateException("The root directory for the calabash-tests could not be found: '${workingDir}'")
}
if (!(new File(workingDir, "features").exists())) {
throw new IllegalStateException("The required 'features' directory could not be found in '${workingDir}'")
}
outputFile.parentFile.mkdirs()
def calabashCmd = "cd ${workingDir.canonicalPath}\r\necho calabash-android run \"${apkFile.canonicalPath}\" --format html --out \"${outputFile.canonicalPath}\"\r\n"
getCommandFile().write calabashCmd
}
protected execute(Exec exec) {
exec.commandLine 'cmd', '/c', getCommandFile().canonicalPath
}
protected clean() {
outputFile.delete()
}
private File getCommandFile() {
if (!tmpFile) {
tmpFile = File.createTempFile("run-calabash", ".bat")
tmpFile.deleteOnExit()
}
return tmpFile
}
}