如何使用gradle进行黄瓜测试

use*_*712 9 java cucumber-jvm

我在Gradle中运行Cucumber测试时遇到问题.我正在使用cucumber-jvm.

TestNGCucumberRunner扩展了AbstractTestNGCucumberTests和testng注释@beforesuite,@aftersuite..

我通常TestNGCucumberRunner.java通过右键单击在IntelliJ中运行它并成功运行.现在我想

  1. 在gradle中调用TestNGCucumberRunner.java

要么

  1. 调用gradle中的所有功能

我试图将testNGCucumberRunner.java作为javaexec执行但是失败了.

我试图执行包中的所有功能文件.我也用过apply plugin: 'com.github.samueltbrown.cucumber'.

Car*_*ini 9

更新:

我的设置使用了一个不同的插件,支持并行执行场景,更好的报告,并且仍然可以主动维护:

的build.gradle

plugins {
  ...
  id "com.commercehub.cucumber-jvm" version "0.11"
}

addCucumberSuite 'cucumberTest'

dependencies {
  ...
  cucumberTestCompile 'info.cukes:cucumber-java:1.2.5'  // or -java8 if you prefer lambda notation

}
Run Code Online (Sandbox Code Playgroud)

目录结构:

??? src
    ??? cucumberTest
    ?   ??? java
    ?   ?   ??? package1 
    ?           ???       <- Glue
    ?   ??? resources    
    ?       ??? package2 
    ?           ???       <- Features
    ??? main
    ?   ??? java
    ??? test
        ??? java
Run Code Online (Sandbox Code Playgroud)

可以在build.gradle文件中指定package1package2名称(以及许多其他选项)


之前使用黄瓜为gradle使用黄瓜的设置.

的build.gradle

plugins {
    id "java"
    id "com.github.samueltbrown.cucumber" version "0.9"
  }   

dependencies {
    cucumberCompile 'info.cukes:cucumber-java:1.2.4'
}

cucumber {
    formats = ['pretty','junit:build/cucumber.xml']
}
Run Code Online (Sandbox Code Playgroud)

目录布局

??? src
    ??? cucumber
    ?   ??? java         <- Glue
    ?   ??? resources    <- Features
    ??? main
    ?    ??? java
    ??? test
        ??? java
Run Code Online (Sandbox Code Playgroud)

命令

gradle cucumber
Run Code Online (Sandbox Code Playgroud)


Mig*_*yes 6

我选择不使用com.github.samueltbrown.cucumber插件,它最后一次更新是在 2015 年 8 月。相反,我创建了一个我可以独立构建的“integrationTest”(cucumber)源集。即,一个简单的gradle build将构建testintegrationTest源集。如果我只想运行集成测试,我可以运行gradle integrationTest -x test,或者我只能使用gradle test -x integrationTest.

我遵循的步骤在这里:http : //www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/

但这里是总结:

构建.gradle

sourceSets {
    integrationTest {
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integrationTest/java')
        }
        resources.srcDir file('src/integrationTest/resources')
    }
}

//Ensure that the integrationTestCompile/integrationTestRuntime configuration contains the dependencies that are required to compile/run our unit tests.
configurations {
    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntime.extendsFrom testRuntime
}

task integrationTest(type: Test) {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath

    // Gradle skips tasks whose input and output are up to date.
    // To ensure that your integration tests are run every time,
    // tell Gradle that the outputs of the integrationTest task should always be considered out of date.
    outputs.upToDateWhen { false }
}

// Ensure that our integration tests are run before the check task and that the check task fails the build if there are failing integration tests.
// Ensure that our unit tests are run before our integration tests. This guarantees that our unit tests are run even if our integration tests fails.
check.dependsOn integrationTest
integrationTest.mustRunAfter test

// Ensure that the HTML reports of unit and integration tests are created to different report
// build/reports/integrationTest directory contains the HTML report that contains the test results of our integration tests.
tasks.withType(Test) {
    reports.html.destination = file("${reporting.baseDir}/${name}")
}

def cucumberVersion = "1.2.4"

dependencies {
    integrationTestCompile(
            'info.cukes:cucumber-core:' + cucumberVersion,
            'info.cukes:cucumber-java:' + cucumberVersion,
            'info.cukes:cucumber-java:' + cucumberVersion,
            'info.cukes:cucumber-junit:' + cucumberVersion,
            'info.cukes:cucumber-spring:' + cucumberVersion,
            'org.springframework:spring-beans:4.2.5.RELEASE'
    )
    integrationTestRuntime(
            'org.springframework:spring-context:4.2.5.RELEASE',
            'org.springframework:spring-test:4.2.5.RELEASE',
            'org.springframework:spring-tx:4.2.5.RELEASE'
    )
}
Run Code Online (Sandbox Code Playgroud)