Spring Boot + Serenity + Cucumber for Rest API 集成测试
Spring Boot + Serenity + Cucumber for Rest API Integration Test
我正在使用 gradle 项目,并且我遵循了 CucumberSerenity 和 Spring 通过使用此 link 引导集成方法:https://medium.com/@manu.me/bdd-simplified-with-springboot-b56ffdcadb2b
当我 运行 gradle 任务 cucumber 时,我收到以下错误消息
SEVERE: Exception while executing pickle
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Killable
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:108)
at net.serenitybdd.cucumber.cli.Main.run(Main.java:31)
at net.serenitybdd.cucumber.cli.Main.main(Main.java:19)
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Killable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access0(URLClassLoader.java:73)
at java.net.URLClassLoader.run(URLClassLoader.java:368)
at java.net.URLClassLoader.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at net.thucydides.core.webdriver.SupportedWebDriver.<clinit>(SupportedWebDriver.java:31)
at net.thucydides.core.configuration.WebDriverConfiguration.lookupSupportedDriverTypeFor(WebDriverConfiguration.java:49)
at net.thucydides.core.configuration.WebDriverConfiguration.getDriverType(WebDriverConfiguration.java:33)
at net.thucydides.core.webdriver.SerenityWebdriverManager.getDefaultDriverType(SerenityWebdriverManager.java:178)
at net.thucydides.core.webdriver.SerenityWebdriverManager.getWebdriver(SerenityWebdriverManager.java:116)
at net.thucydides.core.webdriver.ThucydidesWebDriverSupport.getDriver(ThucydidesWebDriverSupport.java:147)
at net.thucydides.core.webdriver.ThucydidesWebDriverSupport.getPages(ThucydidesWebDriverSupport.java:208)
at net.serenitybdd.core.Serenity.getPages(Serenity.java:188)
at net.serenitybdd.core.Serenity.getDefaultDependencyInjectors(Serenity.java:84)
at net.serenitybdd.core.Serenity.getDependencyInjectors(Serenity.java:74)
at net.serenitybdd.core.Serenity.resetDependencyInjectors(Serenity.java:67)
at net.serenitybdd.core.Serenity.done(Serenity.java:167)
at cucumber.runtime.SerenityObjectFactory.stop(SerenityObjectFactory.java:31)
at io.cucumber.core.runner.Runner.disposeBackendWorlds(Runner.java:175)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:70)
at io.cucumber.core.runtime.Runtime.lambda$run(Runtime.java:100)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:243)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at io.cucumber.core.runtime.Runtime.lambda$run(Runtime.java:100)
at java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:193)
at java.util.stream.SliceOps.accept(SliceOps.java:204)
at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1359)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:101)
... 2 more
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.internal.Killable
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 46 more
Aug 13, 2020 12:22:47 PM io.cucumber.core.runtime.Runtime run
SEVERE: Exception while executing pickle
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class net.thucydides.core.webdriver.SupportedWebDriver
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:108)
at net.serenitybdd.cucumber.cli.Main.run(Main.java:31)
at net.serenitybdd.cucumber.cli.Main.main(Main.java:19)
build.gradle
请参考我试图从命令 prompt/terminal
执行的任务 cucumber
buildscript {
repositories {
mavenLocal()
}
dependencies{
classpath('net.serenity-bdd:serenity-gradle-plugin:2.2.9')
}
}
// Apply Plugins & Custom Configurations
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'net.serenity-bdd.aggregator'
// Set values from properties
processResources {
filesMatching('**/*.properties') { expand(project.properties) }
}
// Following two block required for spring boot plugin as no main class
bootRepackage {
enabled = false
}
project.afterEvaluate {
if (!project.plugins.hasPlugin(ApplicationPlugin)) {
project.plugins.apply(ApplicationPlugin)
project.tasks.withType(CreateStartScripts) { CreateStartScripts task ->
task.enabled = false
}
}
}
// *************************************
// Java Properties and Depenedencies
sourceCompatibility = 1.8
targetCompatibility = 1.8
//Application Test Source Set and Dependencies
configurations {
//providedRuntime
applicationTestCompile.extendsFrom testCompile {
all*.exclude group: 'com.assertthat', module: 'selenium-shutterbug'
}
applicationTestRuntime.extendsFrom testRuntime
}
ext {
applicationTestBase= "src/applicationTest"
}
sourceSets {
applicationTest {
java.srcDir "$projectDir/$applicationTestBase/java"
resources {
srcDirs = ["$applicationTestBase/resources"]
}
compileClasspath += sourceSets.main.compileClasspath //+ sourceSets.test.compileClasspath
runtimeClasspath += sourceSets.main.runtimeClasspath //+ sourceSets.test.runtimeClasspath
}
}
dependencies {
applicationTestCompile "org.springframework.boot:spring-boot-starter-test"
applicationTestCompile "com.jayway.restassured:rest-assured"
//database dependencies
applicationTestCompile "org.springframework.boot:spring-boot-starter-data-jpa"
applicationTestCompile "com.oracle:ojdbc7"
//Serenity & Cucumber Dependencies
applicationTestCompile 'io.rest-assured:rest-assured:3.3.0'
compile(group: 'com.jayway.jsonpath', name: 'json-path', version:'2.4.0') {
exclude(module: 'slf4j-api')
}
compile ('net.serenity-bdd:serenity-gradle-plugin:2.2.9') {
exclude group: 'com.google.inject', module:'guice'
exclude group: 'io.cucumber', module: 'cucumber-core'
exclude group: 'io.cucumber', module: 'cucumber-java'
}
compile ('net.serenity-bdd:serenity-core:2.2.9'){
exclude group: 'io.cucumber', module: 'cucumber-core'
}
applicationTestCompile ('net.serenity-bdd:serenity-cucumber5:2.2.5')
applicationTestCompile 'net.serenity-bdd:serenity-single-page-report:2.2.9'
applicationTestCompile 'net.serenity-bdd:serenity-model:2.2.9'
applicationTestCompile 'net.serenity-bdd:serenity-junit:2.2.9'
applicationTestCompile 'net.serenity-bdd:serenity-stats:2.2.9'
applicationTestCompile 'net.serenity-bdd:serenity-screenplay:2.2.9'
applicationTestCompile 'net.serenity-bdd:serenity-rest-assured:2.2.9'
applicationTestCompile 'net.serenity-bdd:serenity-screenplay-webdriver:2.2.9'
applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-api', version: '3.141.59'
// applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-api', version: '2.29.1' -- internal/killable
applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-remote-driver', version: '3.14.0'
applicationTestCompile group: 'org.seleniumhq.selenium', name: 'htmlunit-driver', version: '2.37.0'
applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.141.59'
applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-safari-driver', version: '3.141.59'
applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.141.59'
applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.14.0'
applicationTestCompile 'org.seleniumhq.selenium:selenium-server:3.14.0'
applicationTestCompile group: 'org.springframework', name: 'spring-jms', version: '5.1.6.RELEASE'
applicationTestCompile "com.ibm.mq:com.ibm.mq.allclient:9.0.4.0"
applicationTestCompile group: 'org.assertj', name: 'assertj-core', version:'3.6.2'
applicationTestCompile group: 'org.apache.commons', name: 'commons-csv', version:'1.5'
applicationTestCompile group: 'org.apache.maven.plugins', name: 'maven-failsafe-plugin', version: '3.0.0-M5'
}
task cucumber() {
dependsOn assemble, testClasses
doLast {
javaexec {
main = "net.serenitybdd.cucumber.cli.Main"
classpath = configurations.applicationTestRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin', 'pretty', '--glue', 'gradle.clean.aggregate', 'src/applicationTest/resources']
}
}
}
// Application Test Runners
task runApplicationTest(type: Test) {
outputs.upToDateWhen { false }
include '**/*Runner.java'
systemProperties(System.getProperties())
testClassesDir = project.sourceSets.applicationTest.output.classesDir
classpath = project.sourceSets.applicationTest.runtimeClasspath
reports.html.destination = project.file("$reports.html.destination/applicationTest")
reports.junitXml.destination = project.file("$reports.junitXml.destination/applicationTest")
maxHeapSize = "2G"
jvmArgs '-XX:MaxPermSize=256m'
}
Runner.java - 我将 运行 与“CucumberWithSerenity”一起使用,并将 @ActiveProfiles 与我的其他[=17] link 一起使用=]
import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features="./src/applicationTest/resources/features/sample.feature", glue={"definitions"}, tags={"@test"},strict = true)
@ActiveProfiles("test")
public class Runner{
}
定义文件
@SpringBootTest
public class SampleDefinitions{
@Given("^user sends message\"([^\"]*)\"$")
public void user_sends_message(String usermessage){
System.out.println("usermessage -->"+usermessage);
}
}
当 classes 在 运行 时间不可用时会发生这种情况。
您正在使用自定义源集,即 applicationTest
未正确配置 运行 cucumber 任务。
一个解决方案是更改 cucumber 任务中的 class 路径,并包括主要源集以使用 applicationTest classes
- 黄瓜任务
classpath = sourceSets.applicationTest.runtimeClasspath
- 源集
main {
compileClasspath += applicationTest.output
runtimeClasspath += applicationTest.output
}
这应该有效。
有这个 spring、cucumber/ghjerkin 库可以轻松测试冲刺休息 api:https://github.com/RedFroggy/spring-cucumber-rest-api
我正在使用 gradle 项目,并且我遵循了 CucumberSerenity 和 Spring 通过使用此 link 引导集成方法:https://medium.com/@manu.me/bdd-simplified-with-springboot-b56ffdcadb2b 当我 运行 gradle 任务 cucumber 时,我收到以下错误消息
SEVERE: Exception while executing pickle
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Killable
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:108)
at net.serenitybdd.cucumber.cli.Main.run(Main.java:31)
at net.serenitybdd.cucumber.cli.Main.main(Main.java:19)
Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Killable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access0(URLClassLoader.java:73)
at java.net.URLClassLoader.run(URLClassLoader.java:368)
at java.net.URLClassLoader.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at net.thucydides.core.webdriver.SupportedWebDriver.<clinit>(SupportedWebDriver.java:31)
at net.thucydides.core.configuration.WebDriverConfiguration.lookupSupportedDriverTypeFor(WebDriverConfiguration.java:49)
at net.thucydides.core.configuration.WebDriverConfiguration.getDriverType(WebDriverConfiguration.java:33)
at net.thucydides.core.webdriver.SerenityWebdriverManager.getDefaultDriverType(SerenityWebdriverManager.java:178)
at net.thucydides.core.webdriver.SerenityWebdriverManager.getWebdriver(SerenityWebdriverManager.java:116)
at net.thucydides.core.webdriver.ThucydidesWebDriverSupport.getDriver(ThucydidesWebDriverSupport.java:147)
at net.thucydides.core.webdriver.ThucydidesWebDriverSupport.getPages(ThucydidesWebDriverSupport.java:208)
at net.serenitybdd.core.Serenity.getPages(Serenity.java:188)
at net.serenitybdd.core.Serenity.getDefaultDependencyInjectors(Serenity.java:84)
at net.serenitybdd.core.Serenity.getDependencyInjectors(Serenity.java:74)
at net.serenitybdd.core.Serenity.resetDependencyInjectors(Serenity.java:67)
at net.serenitybdd.core.Serenity.done(Serenity.java:167)
at cucumber.runtime.SerenityObjectFactory.stop(SerenityObjectFactory.java:31)
at io.cucumber.core.runner.Runner.disposeBackendWorlds(Runner.java:175)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:70)
at io.cucumber.core.runtime.Runtime.lambda$run(Runtime.java:100)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:243)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at io.cucumber.core.runtime.Runtime.lambda$run(Runtime.java:100)
at java.util.stream.ReferencePipeline.accept(ReferencePipeline.java:193)
at java.util.stream.SliceOps.accept(SliceOps.java:204)
at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1359)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:101)
... 2 more
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.internal.Killable
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 46 more
Aug 13, 2020 12:22:47 PM io.cucumber.core.runtime.Runtime run
SEVERE: Exception while executing pickle
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class net.thucydides.core.webdriver.SupportedWebDriver
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:108)
at net.serenitybdd.cucumber.cli.Main.run(Main.java:31)
at net.serenitybdd.cucumber.cli.Main.main(Main.java:19)
build.gradle
请参考我试图从命令 prompt/terminal
执行的任务 cucumberbuildscript { repositories { mavenLocal() } dependencies{ classpath('net.serenity-bdd:serenity-gradle-plugin:2.2.9') } } // Apply Plugins & Custom Configurations apply plugin: 'java' apply plugin: 'maven' apply plugin: 'org.springframework.boot' apply plugin: 'net.serenity-bdd.aggregator' // Set values from properties processResources { filesMatching('**/*.properties') { expand(project.properties) } } // Following two block required for spring boot plugin as no main class bootRepackage { enabled = false } project.afterEvaluate { if (!project.plugins.hasPlugin(ApplicationPlugin)) { project.plugins.apply(ApplicationPlugin) project.tasks.withType(CreateStartScripts) { CreateStartScripts task -> task.enabled = false } } } // ************************************* // Java Properties and Depenedencies sourceCompatibility = 1.8 targetCompatibility = 1.8 //Application Test Source Set and Dependencies configurations { //providedRuntime applicationTestCompile.extendsFrom testCompile { all*.exclude group: 'com.assertthat', module: 'selenium-shutterbug' } applicationTestRuntime.extendsFrom testRuntime } ext { applicationTestBase= "src/applicationTest" } sourceSets { applicationTest { java.srcDir "$projectDir/$applicationTestBase/java" resources { srcDirs = ["$applicationTestBase/resources"] } compileClasspath += sourceSets.main.compileClasspath //+ sourceSets.test.compileClasspath runtimeClasspath += sourceSets.main.runtimeClasspath //+ sourceSets.test.runtimeClasspath } } dependencies { applicationTestCompile "org.springframework.boot:spring-boot-starter-test" applicationTestCompile "com.jayway.restassured:rest-assured" //database dependencies applicationTestCompile "org.springframework.boot:spring-boot-starter-data-jpa" applicationTestCompile "com.oracle:ojdbc7" //Serenity & Cucumber Dependencies applicationTestCompile 'io.rest-assured:rest-assured:3.3.0' compile(group: 'com.jayway.jsonpath', name: 'json-path', version:'2.4.0') { exclude(module: 'slf4j-api') } compile ('net.serenity-bdd:serenity-gradle-plugin:2.2.9') { exclude group: 'com.google.inject', module:'guice' exclude group: 'io.cucumber', module: 'cucumber-core' exclude group: 'io.cucumber', module: 'cucumber-java' } compile ('net.serenity-bdd:serenity-core:2.2.9'){ exclude group: 'io.cucumber', module: 'cucumber-core' } applicationTestCompile ('net.serenity-bdd:serenity-cucumber5:2.2.5') applicationTestCompile 'net.serenity-bdd:serenity-single-page-report:2.2.9' applicationTestCompile 'net.serenity-bdd:serenity-model:2.2.9' applicationTestCompile 'net.serenity-bdd:serenity-junit:2.2.9' applicationTestCompile 'net.serenity-bdd:serenity-stats:2.2.9' applicationTestCompile 'net.serenity-bdd:serenity-screenplay:2.2.9' applicationTestCompile 'net.serenity-bdd:serenity-rest-assured:2.2.9' applicationTestCompile 'net.serenity-bdd:serenity-screenplay-webdriver:2.2.9' applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-api', version: '3.141.59' // applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-api', version: '2.29.1' -- internal/killable applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-remote-driver', version: '3.14.0' applicationTestCompile group: 'org.seleniumhq.selenium', name: 'htmlunit-driver', version: '2.37.0' applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.141.59' applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-safari-driver', version: '3.141.59' applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.141.59' applicationTestCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.14.0' applicationTestCompile 'org.seleniumhq.selenium:selenium-server:3.14.0' applicationTestCompile group: 'org.springframework', name: 'spring-jms', version: '5.1.6.RELEASE' applicationTestCompile "com.ibm.mq:com.ibm.mq.allclient:9.0.4.0" applicationTestCompile group: 'org.assertj', name: 'assertj-core', version:'3.6.2' applicationTestCompile group: 'org.apache.commons', name: 'commons-csv', version:'1.5' applicationTestCompile group: 'org.apache.maven.plugins', name: 'maven-failsafe-plugin', version: '3.0.0-M5' } task cucumber() { dependsOn assemble, testClasses doLast { javaexec { main = "net.serenitybdd.cucumber.cli.Main" classpath = configurations.applicationTestRuntime + sourceSets.main.output + sourceSets.test.output args = ['--plugin', 'pretty', '--glue', 'gradle.clean.aggregate', 'src/applicationTest/resources'] } } } // Application Test Runners task runApplicationTest(type: Test) { outputs.upToDateWhen { false } include '**/*Runner.java' systemProperties(System.getProperties()) testClassesDir = project.sourceSets.applicationTest.output.classesDir classpath = project.sourceSets.applicationTest.runtimeClasspath reports.html.destination = project.file("$reports.html.destination/applicationTest") reports.junitXml.destination = project.file("$reports.junitXml.destination/applicationTest") maxHeapSize = "2G" jvmArgs '-XX:MaxPermSize=256m' }
Runner.java - 我将 运行 与“CucumberWithSerenity”一起使用,并将 @ActiveProfiles 与我的其他[=17] link 一起使用=]
import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features="./src/applicationTest/resources/features/sample.feature", glue={"definitions"}, tags={"@test"},strict = true)
@ActiveProfiles("test")
public class Runner{
}
定义文件
@SpringBootTest
public class SampleDefinitions{
@Given("^user sends message\"([^\"]*)\"$")
public void user_sends_message(String usermessage){
System.out.println("usermessage -->"+usermessage);
}
}
当 classes 在 运行 时间不可用时会发生这种情况。
您正在使用自定义源集,即 applicationTest
未正确配置 运行 cucumber 任务。
一个解决方案是更改 cucumber 任务中的 class 路径,并包括主要源集以使用 applicationTest classes
- 黄瓜任务
classpath = sourceSets.applicationTest.runtimeClasspath
- 源集
main {
compileClasspath += applicationTest.output
runtimeClasspath += applicationTest.output
}
这应该有效。
有这个 spring、cucumber/ghjerkin 库可以轻松测试冲刺休息 api:https://github.com/RedFroggy/spring-cucumber-rest-api