如何使用gradle进行黄瓜测试

问题描述 投票:9回答:3

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

TestNGCucumberRunnerAbstractTestNGCucumberTests@beforesuite扩展了@aftersuite和testng注释。

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

  1. 在gradle中调用TestNGCucumberRunner.java

要么

  1. 调用gradle中的所有功能

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

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

java cucumber-jvm
3个回答
8
投票

更新:

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

的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

}

目录结构:

└── src
    ├── cucumberTest
    │   ├── java
    │   │   └── package1 
    │           └──       <- Glue
    │   └── resources    
    │       └── package2 
    │           └──       <- Features
    ├── main
    │   └── java
    └── test
        └── java

可以在build.gradle文件中指定package1和package2名称(以及许多其他options


我之前使用黄瓜为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']
}

目录布局

└── src
    ├── cucumber
    │   ├── java         <- Glue
    │   └── resources    <- Features
    └── main
    │    └── java
    └── test
        └── java

命令

gradle cucumber

4
投票

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

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

但这里是摘要:

的build.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'
    )
}

4
投票

你可以阅读官方文件。

https://docs.cucumber.io/tools/java/#gradle

© www.soinside.com 2019 - 2024. All rights reserved.