自动化 Rest API 测试并将其与持续集成(CI-Jenkins)集成 [英] Automate Rest API test and integrate this with Continuous Integration(CI-Jenkins)

查看:27
本文介绍了自动化 Rest API 测试并将其与持续集成(CI-Jenkins)集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了许多与此相关的类似问题,但不是我正在寻找的特定答案.其实我的需求有点不同,所以我最终发布了以下问题.

I found many similar questions related to this, but not the particular answer I am looking for. Actually my requirement is little different, so I end up posting the following issue.

我想自动化 Rest API,对于同一个案例,我有两个选择.第一个是Rest Assured,第二个是Play Framework.

I want to automate Rest APIs, and I got two options for the same case. The first one is Rest Assured and second one is Play Framework.

例如,要测试这个 RestAPI:

For example, to test this RestAPI:

http://servername:9000/dbs/all/list/m1/p1/sch1

(↑ 这给出了 xml 响应)

(↑ This gives xml response)

所以,我用 Java 编写了一个代码,放心,并且运行良好.我将其与 Maven 项目集成,以便可以与 Jenkins 集成.示例代码:

So, I have written a code in Java with Rest assured, and is working fine. I integrate this with Maven project so that can be integrated with Jenkins. Sample code:

   import com.jayway.restassured
    public class TestNGSimpleTest2 {

        @Test
        public void testApi() {
                expect().
                statusCode(200).
                body("Status", equalTo("Su22ccess")).
                when().
                get("http://localhost:9000/dbs/all/list/m1/p1/sch1");

        }

所以我的第一个问题是:

So my first question is:

  1. 放心是最好用的工具吗?
  2. Play 框架更好吗?
  3. 我发现了许多其他工具,如 Jmeter、RightAPI 等,用于测试 RestAPI.但我不认为这是自动化的.我说得对吗?

推荐答案

对于自动化 REST API 测试,作为起点,我建议使用 邮递员newman.

For automating REST API testing, as a starting point I recommend using Postman and newman.

Postman 为构建请求提供了出色的 UI,而 newman 是它的命令行对应物.在 Postman UI 中创建一组请求和相应的测试后,您可以通过 newman 从 Jenkins 运行整个集合,防止在测试失败时进行部署.

Postman provides an excellent UI for building requests, and newman is its command-line counterpart. After you create a set of requests and corresponding tests within the Postman UI, you can run the entire collection from Jenkins via newman, preventing a deployment if tests fail.

这篇关于自动化 Rest API 测试并将其与持续集成(CI-Jenkins)集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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