自动化Rest API测试,并将其与持续集成(CI-Jenkins)集成 [英] Automate Rest API test and integrate this with Continuous Integration(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 posting this.
我想自动化Rest API,我有2个相同的选项. 第一个是确保放心",第二个是播放"框架.
I want to automate Rest APIs , and I got 2 options for same. 1st one is Rest Assured and second one is Play framework.
例如.测试此RestAPI,
For exa. to test this RestAPI,
http://servername:9000/dbs/all/list/m1/p1/sch1
(这会给出xml响应) 我已经用Java编写了代码,请放心,并且工作正常.我将此与Maven项目集成在一起,以便可以与Jenkins集成. 示例代码:
(This gives xml response) I have written a code in Java with Rest assured, and is working fine. I integrate this with Maven project so that can be integarted 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");
}
所以我的第一个问题是: 1.放心使用最好的工具吗? 2. Play框架会更好吗? 3.我发现了许多其他工具,例如Jmeter,RightAPI等,来测试RestAPI.但是我不认为这是自动化的.我说的对吗?
So my first question is: 1. Is the rest assured is the best tool to use? 2. Does Play framework is better? 3. I found many other tool like Jmeter, RightAPI etc. to test RestAPI. But I dont think this is automable. Am I right?
推荐答案
对于自动化REST API测试,我建议使用纽曼.
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屋!