如何让gradle和黄瓜一起工作?

时间:2015-12-18 12:19:49

标签: java 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或黄瓜有特定的限制来防止这种情况?

2 个答案:

答案 0 :(得分: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

的函数
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"
}

答案 1 :(得分:0)

请在 build.gradle 文件中使用以下gradle cuc插件

插件{     id'java'     id“com.github.samueltbrown.cucumber”version“0.9” }

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

在终端中运行 gradle cucumber 将开始

相关问题