Str*_*ton 12 ruby android cucumber calabash android-studio
我在64位Windows 7上使用Android Studio.我是Android Studio(或任何Intelij IDE)的noobie.
我下载并安装了Ruby 1.9.3,Ruby DevKit和calabash-android,我可以使用命令行在我的Android应用程序上成功运行Cucumber测试(calabash-android run)
我还设法为Android Studio安装了Cucumber插件,这样我的功能文件就可以从自动完成等方面受益.
我有以下问题:
我可以安装Ruby插件(RubyMine?),以便我可以为我的测试编写步骤定义吗?如果是这样,我听说人们可以调试Cucumber测试:这可以在Android Studio for Android应用程序中实现吗?
我可以从Android Studio为Android应用启动calabash测试吗?如果是这样,我该怎么办呢?
我可以在Gradle构建的Android应用程序中使用calabash集成(自动)测试吗?如果是这样,我该怎么办呢?
谢谢!
更新:
我附上了一个自定义的gradle Plugin<Project>
(请参阅我编写的下面的凹槽代码,以获得运行calabash-android测试的基本支持.
这些手动步骤仍然是必要的:
- 安装Ruby 1.9.x及其Devkit,安装calabash-android gem等.
- 使用android gradle插件(手动或自动)构建适当的(风味的)APK
在应用程序中build.gradle
,添加apply plugin: 'calabash'
现在可以工作,它允许构建运行功能文件作为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
}
}
Run Code Online (Sandbox Code Playgroud)
非常好的问题。Xamarin 举办了一次关于在其 Test Cloud 产品中使用 Calabash 测试的网络研讨会。在演讲接近尾声时,有相当多的实践内容涉及设置测试生态系统和运行 Android 的 Calabash 测试。其中有很多内容不适用于您的环境,但 Karl Krukow(calabash-android 的主要贡献者之一)提供了一些非常好的技巧和见解。
归档时间: |
|
查看次数: |
3291 次 |
最近记录: |