小编jer*_*797的帖子

如何通过 RestAssured 重用常见断言

我有一些使用 RestAssured 的 java 测试。对于许多测试,given() 和when() 参数不同,但then() 部分是相同的并且由多个assertThat() 语句组成。如何将 then() 块移动到可以反复使用的新方法?

@Test
public void test_inAppMsgEmptyResponse() {
    given().
            contentType("application/json").
    when().
            get("inapp/messages.json").
    then().assertThat().
            statusCode(HttpStatus.SC_OK).
            assertThat().
            body("pollInterval", equalTo(defaultPollInterval)).
            assertThat().
            body("notifications", hasSize(0));
}
Run Code Online (Sandbox Code Playgroud)

java dry

0
推荐指数
1
解决办法
1881
查看次数

标签 统计

dry ×1

java ×1