【问题标题】:How to get gradle and cucumber working together?如何让 gradle 和 cucumber 一起工作?
【发布时间】:2015-12-18 12:19:48
【问题描述】:

让 gradle 干净地使用 cucumber 是一个挑战。我想让gradle build 编译和运行测试,但到目前为止我还没有成功。

build.gradle

plugins {
   id "com.github.samueltbrown.cucumber" version "0.9"
}
apply plugin: 'java'
apply plugin: 'idea'


def JAVA_WEBSOCKET_VERSION = '1.2.1'
def CUCUMBER_VERSION = '1.2.4'
jar {
    manifest {
        attributes 'Implementation-Title': 'Java-WebSocket',
                   'Implementation-Version': JAVA_WEBSOCKET_VERSION
    }
}

repositories {
    jcenter()
}

dependencies {
    testCompile "info.cukes:cucumber-java:$CUCUMBER_VERSION"
    testCompile "info.cukes:cucumber-junit:$CUCUMBER_VERSION"
    testCompile 'junit:junit:4.+'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}

目前我收到很多关于黄瓜使用的注释(@Given@Then@After)的错误。我想要的是在不使用 JavaExec 的情况下干净地构建项目。这是可能的,还是对 gradle 或 cucumber 有特定的限制来防止这种情况发生?

【问题讨论】:

  • 您的设置看起来正确,我使用相同的依赖项。您的目录结构是什么?什么时候出现这些错误?
  • gradle build 期间。 jar 构建,依赖项下载,但每个黄瓜注释都失败。我只是设法使用 JavaExec 并调用自定义任务让它工作,这不是很好。
  • 结构怎么样?您在主要或测试中有您的步骤定义吗?因为您正在构建 jar,所以我猜您在 main 中有它们。但依赖只在test

标签: java gradle cucumber


【解决方案1】:
dependencies {

    testCompile 'info.cukes:cucumber-jvm:1+'
    testCompile 'info.cukes:cucumber-jvm-deps:1+'
    testCompile 'info.cukes:cucumber-java:1+'
    testCompile 'info.cukes:cucumber-junit:1+'
    testCompile 'info.cukes:cucumber-core:1+'

}

我创建了另一个函数来执行测试

test { 

    ignoreFailures = true


    // show standard out and standard error of the test JVM(s) on the console
    testLogging.showStandardStreams = true

    // set heap size for the test JVM(s)
    minHeapSize = "128m"
    maxHeapSize = "512m"

    // set JVM arguments for the test JVM(s)
    jvmArgs '-XX:MaxPermSize=256m'

    // listen to events in the test execution lifecycle
    beforeTest { descriptor ->
        logger.lifecycle("Running test: " + descriptor)
    }


    // explicitly include or exclude tests( Add Package directly)
    exclude "com/**/***/rest/junit**"
    exclude "com/**/***/db/junit**"

    reports.junitXml.enabled = false
    reports.html.enabled = false
}

现在从命令行调用这个函数来执行测试

task "forceTest" { 
    dependsOn "clean", "cleanTest", "test"
}

【讨论】:

  • 依赖项将解决您所有的@before 和其他标签问题。
  • 依赖,不修复它。
【解决方案2】:

请在您的 build.gradle 文件中使用以下 gradle cucumber 插件

插件{ 标识“java” id "com.github.samueltbrown.cucumber" 版本 "0.9" }

依赖{ testCompile 组:'junit',名称:'junit',版本:'4.11' 编译'org.codehaus.groovy:groovy:2.4.7' cucumberCompile 'info.cukes:cucumber-groovy:1.2.2' }

在终端中运行gradle cucumber会让你开始

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 2015-10-01
    • 2017-06-11
    • 2014-01-12
    相关资源
    最近更新 更多