简体   繁体   English

如何在Serenity测试中指定测试跑步者?

[英]How do I specify test runner in Serenity tests?

I created a serenity + JBehave + spring boot test. 我创建了一个宁静+ JBehave +弹簧启动测试。

The test looks as follows: 该测试如下所示:

Story: 故事:

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

Test: 测试:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = TestServer.class)
@WebAppConfiguration
@IntegrationTest({ "server.port=6666" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class UserRegistrationTest extends SerenityStory {

    private String email;

    private String password;

    @Steps
    private UserRegistrationSteps userRegistrationSteps;

    @Given("a user with email address '$email' and password '$password'")
    public void givenAUserWithEmailAndPassword(@Named("email") String email, @Named("password") String password) {
        this.email = email;
        this.password = password;
    }

    @When("attempt to register")
    public void attemptToRegister() {
        userRegistrationSteps.openRegistrationPage();

        userRegistrationSteps.enterRegistrationCredentials(email, password);
    }

    @Then("system returns an information about password being too short")
    public void thenSystemReturnsAnInformationAboutPasswordBeingTooShort() {
        userRegistrationSteps.makeSureRegistrationErrorsContainErrorAboutShortPassword();
    }
}

When I run the test separately everything goes smoothly. 当我分别运行测试时,一切都会顺利进行。 First spring boot server starts, it generates some temporary in-memory database and only then the test is executed. 首先,Spring Boot服务器启动,它生成一些临时的内存数据库,然后才执行测试。 If you run the test separately from the other however, the report is not generated. 但是,如果您单独运行测试,则不会生成报告。 In order to generate reports I need to execute 为了生成报告,我需要执行

gradle test aggregate Gradle测试聚合

unfortunately, when I do that serenity forgets that I have the @RunWith(SpringJUnit4ClassRunner.class) annotation at all. 不幸的是,当我这样做时,宁静忘了我根本没有@RunWith(SpringJUnit4ClassRunner.class)批注。 It tries to run the test on the server that doesn't yet exist and as a result the test fails. 它尝试在尚不存在的服务器上运行测试,结果测试失败。

Here's also my build.gradle 这也是我的build.gradle

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'
}

so how do I make serenity take the @RunWith annotation into account when generating reports, so that my server for the tests is actually generated? 因此,在生成报告时如何使@RunWith注释考虑在内,从而使我的测试服务器真正生成?

I think you might need to use some kind of SerenityRunner instead of SpringJunit4TestRunner. 我认为您可能需要使用某种SerenityRunner而不是SpringJunit4TestRunner。 However this is a little difficult. 但是,这有点困难。 I've been trying this myself and where I have got to is below. 我一直在自己尝试,下面是我要去的地方。

For some history, you could start with chapter 16 in the Serenity reference documentation. 对于某些历史记录,您可以从Serenity参考文档中的第16章开始。

Integrating with Spring 与Spring整合

Although out of date, I think it is mostly applicable, and you could use the updated classes, which you'll find in their source code: 尽管已经过时了,但我认为它大多数都适用,您可以使用更新的类,您可以在其源代码中找到这些更新的类:

@Rule private final SpringIntegrationMethodRule springIntegrationMethodRule = new SpringIntegrationMethodRule();

and

@ClassRule private static final SpringIntegrationClassRule springIntegrationClassRule = new SpringIntegrationClassRule();

Some more up-to-date information is available about these Serenity rules in the commit for this feature. 提交此功能时,有关这些Serenity规则的一些最新信息可用。

In addition to that, if you're on Spring 4.2.0 or later, the Spring team have actually released a couple of Rules themselves, to be used as an alternative to their SpringJUnit4ClassRunner. 除此之外,如果您使用的是Spring 4.2.0或更高版本,则Spring团队实际上已经发布了一些Rule,可以用作SpringJUnit4ClassRunner的替代。 This is probably the best option if you're on a recent version of Spring. 如果您使用的是Spring的最新版本,那么这可能是最佳选择。

Here is an excellent explanation of how to use the new rules from the Spring team. 这是有关如何使用Spring团队的新规则的出色解释

Update: I haven't actually managed to get this working myself with the above information - at least with Serenity / Cucumber so I have raised an issue with the Serenity project here . 更新:实际上,我还没有设法通过上述信息来使我自己工作-至少与Serenity / Cucumber无关,因此我在此处提出了Serenity项目的问题 I've also asked this follow on question on stackoverflow. 我也问过以下关于stackoverflow的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM