Unit testing 如何在Serenity测试中指定测试运行程序?
我创建了一个serenity+JBehave+spring启动测试 测试如下所示: 故事:Unit testing 如何在Serenity测试中指定测试运行程序?,unit-testing,spring-boot,jbehave,Unit Testing,Spring Boot,Jbehave,我创建了一个serenity+JBehave+spring启动测试 测试如下所示: 故事: Meta: Narrative: As a new user, in order to efficiently use the service I first want to register to the service and then log in. During the process I want to make sure that all validations are properly e
Meta:
Narrative:
As a new user, in order to efficiently use the service I first want to register to the service and then log in.
During the process I want to make sure that all validations are properly executed
Scenario: user registration
Given a user with email address 'test@test.com' and password 'aaa'
When attempt to register
Then system returns an information about password being too short
测试:
当我单独运行测试时,一切都很顺利。首先,spring引导服务器启动,它生成一些临时内存数据库,然后才执行测试。但是,如果单独运行测试,则不会生成报告。为了生成报告,我需要执行
级配试验骨料
不幸的是,当我这样做时,serenity忘记了我有@RunWith(SpringJUnit4ClassRunner.class)注释。它尝试在尚不存在的服务器上运行测试,结果测试失败
这也是我的身材,格雷德尔
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("net.serenity-bdd:serenity-gradle-plugin:1.0.59")
}
}
group 'fi.achivi.server'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'net.serenity-bdd.aggregator'
jar {
baseName = 'achivi'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
gradle.startParameter.continueOnFailure = true
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf', // all spring MVC and spring boot in one dependency
'org.springframework.boot:spring-boot-starter-data-mongodb',
'commons-validator:commons-validator:1.4.1', // utils
'org.apache.commons:commons-lang3:3.4',
'org.springframework.security:spring-security-web:4.0.1.RELEASE', //spring security
'org.springframework.security:spring-security-config:4.0.1.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test',
'cz.jirutka.spring:embedmongo-spring:1.3.1', //mongodb dependencies
'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.48.0',
'net.serenity-bdd:core:1.0.47', // JBehave and serenity stuff
'net.serenity-bdd:serenity-junit:1.0.47',
'net.serenity-bdd:serenity-rest-assured:1.0.59',
'org.assertj:assertj-core:1.7.0',
'org.slf4j:slf4j-simple:1.7.7',
'net.serenity-bdd:serenity-jbehave:1.0.23'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
那么,如何让serenity在生成报告时考虑@RunWith注释,以便实际生成测试服务器?我认为您可能需要使用某种SerenityRunner而不是SpringJunit4TestRunner。然而,这有点困难。我自己也试过了,我要做的就是在下面 对于一些历史,您可以从Serenity参考文档中的第16章开始 虽然已经过时,但我认为它基本上是适用的,您可以使用更新的类,这些类可以在它们的源代码中找到:
@规则
私有最终SpringIntegrationMethodRule SpringIntegrationMethodRule=新的SpringIntegrationMethodRule()代码>
及
@ClassRule
私有静态最终SpringIntegrationClassRule SpringIntegrationClassRule=新SpringIntegrationClassRule()代码>
对于此功能,可以在中找到一些关于这些宁静规则的信息
除此之外,如果您使用的是Spring4.2.0或更高版本,Spring团队实际上已经发布了一些规则,作为SpringJUnit4ClassRunner的替代方案。如果您使用的是最新版本的Spring,那么这可能是最好的选择
下面介绍如何使用Spring团队的新规则
更新:
事实上,我还没有用上述信息来解决这个问题——至少在Serenity/Cucumber方面是这样,所以我对Serenity项目提出了一个问题。我在stackoverflow上也问过这个问题
buildscript {
ext {
springBootVersion = '1.2.5.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("net.serenity-bdd:serenity-gradle-plugin:1.0.59")
}
}
group 'fi.achivi.server'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'net.serenity-bdd.aggregator'
jar {
baseName = 'achivi'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
gradle.startParameter.continueOnFailure = true
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf', // all spring MVC and spring boot in one dependency
'org.springframework.boot:spring-boot-starter-data-mongodb',
'commons-validator:commons-validator:1.4.1', // utils
'org.apache.commons:commons-lang3:3.4',
'org.springframework.security:spring-security-web:4.0.1.RELEASE', //spring security
'org.springframework.security:spring-security-config:4.0.1.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test',
'cz.jirutka.spring:embedmongo-spring:1.3.1', //mongodb dependencies
'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.48.0',
'net.serenity-bdd:core:1.0.47', // JBehave and serenity stuff
'net.serenity-bdd:serenity-junit:1.0.47',
'net.serenity-bdd:serenity-rest-assured:1.0.59',
'org.assertj:assertj-core:1.7.0',
'org.slf4j:slf4j-simple:1.7.7',
'net.serenity-bdd:serenity-jbehave:1.0.23'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}