REST Assured 和多个职位 [英] REST Assured and multiple posts

查看:38
本文介绍了REST Assured 和多个职位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 REST 保证来测试我的登录/注销功能.是否有可能进行 REST 保证测试,发布登录然后发布注销?如果没有,我该如何正确测试?

I'm trying to use REST assured to test my login/logout feature. Is it possible to have a REST assured test that posts to login then posts to logout? If not, how can I test it properly?

推荐答案

只需发送两个 post() 和一个 assert()/expect():

Just send two post() with one assert()/expect() :

import org.junit.Assert;
import org.junit.Test;

import static org.hamcrest.Matchers.*;
import static com.jayway.restassured.RestAssured.*;

@Test
public void loginAndLogout(){
    final String login = randomLogin();
    // First post to login()
    given()
    .queryParam("login", login)
    .queryParam("password", randomPassword())
    .when().post("/login/");    

    // Second post to logout() with an assert
    expect().statusCode(200)
    .given()
    .when().post("/logout/");   
}

这篇关于REST Assured 和多个职位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆