加特林`创建新的'测试,还有另一个对象**需要**应该在jhipster中失败吗?

时间:2017-06-02 17:26:07

标签: jhipster gatling

具有必需的另一个对象的Create new Gatling测试是否会失败?还是我弄坏了什么?这是一个错误吗?

例如,docField上的此测试失败(doctTemplate --many--> docFields),我猜它失败了,因为docField需要docTemplate对象,并且生成的测试不会添加该对象。这是我的测试结果:

================================================================================
2017-06-02 19:06:23                                         100s elapsed
---- Requests ------------------------------------------------------------------
> Global                                                   (OK=400    KO=95    )
> First unauthenticated request                            (OK=100    KO=0     )
> Authentication                                           (OK=100    KO=0     )
> Authenticated request                                    (OK=100    KO=0     )
> Get all docFields                                        (OK=100    KO=0     )
> Create new docField                                      (OK=0      KO=95    )
---- Errors --------------------------------------------------------------------
> status.find.is(201), but actually found 400                        95 (100.0%)

这是班级

公共类DocField实现Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@Column(name = "name", nullable = false)
private String name;

@NotNull
@Lob
@Column(name = "default_value", nullable = false)
private String defaultValue;

@ManyToOne(optional = false)
@NotNull
private DocTemplate docTemplate;

这是测试场景:

val scn = scenario("Test the DocField entity")
        .exec(http("First unauthenticated request")
        .get("/api/account")
        .headers(headers_http)
        .check(status.is(401))
        .check(headerRegex("Set-Cookie", "XSRF-TOKEN=(.*);[\\s]").saveAs("xsrf_token"))).exitHereIfFailed
        .pause(10)
        .exec(http("Authentication")
        .post("/api/authentication")
        .headers(headers_http_authenticated)
        .formParam("j_username", "admin")
        .formParam("j_password", "admin")
        .formParam("remember-me", "true")
        .formParam("submit", "Login")
        .check(headerRegex("Set-Cookie", "XSRF-TOKEN=(.*);[\\s]").saveAs("xsrf_token"))).exitHereIfFailed
        .pause(1)
        .exec(http("Authenticated request")
        .get("/api/account")
        .headers(headers_http_authenticated)
        .check(status.is(200)))
        .pause(10)
        .repeat(2) {
            exec(http("Get all docFields")
            .get("/api/doc-fields")
            .headers(headers_http_authenticated)
            .check(status.is(200)))
            .pause(10 seconds, 20 seconds)
            .exec(http("Create new docField")
            .post("/api/doc-fields")
            .headers(headers_http_authenticated)
            .body(StringBody("""{"id":null, "name":"SAMPLE_TEXT", "defaultValue":"SAMPLE_TEXT"}""")).asJSON
            .check(status.is(201))
            .check(headerRegex("Location", "(.*)").saveAs("new_docField_url"))).exitHereIfFailed
            .pause(10)
            .repeat(5) {
                exec(http("Get created docField")
                .get("${new_docField_url}")
                .headers(headers_http_authenticated))
                .pause(10)
            }
            .exec(http("Delete created docField")
            .delete("${new_docField_url}")
            .headers(headers_http_authenticated))
            .pause(10)
        }

我没有看到DocTemplate的任何创建,因此测试失败。是不是jhipster应该生成测试,所以它在代码生成后立即通过?还是我以某种方式打破了它?

1 个答案:

答案 0 :(得分:1)

我认为你是对的。生成的加特林测试并不完美,可以改进。

但IMO,很难在generator-jhipster中编码,因为在创建DocField之前需要在这里创建一个DocTemplate。如果DocTemplate在创建之前需要另一个实体呢?

生成的加特林测试非常简单,您需要更改代码以适应您的使用案例。这就是我在项目中所做的。