81 testing api rest automation
我想为REST API编写一个自动化测试套件.在我们完成新服务时,我们要检查以确保所有先前创建的服务按预期工作.有关用于实现此目的的最佳工具的任何建议吗?我知道像Apigee这样的工具可以让你一次测试1个服务,但是我们想要一种方法来点击按钮来测试所有服务.
the*_*eon 36
在我的工作中,我们最近整合了几个用Java编写的测试套件来测试我们构建的一些RESTful API.我们的服务可以调用他们依赖的其他RESTful API.我们将它分成两个套房.
我肯定会建议这样做.它对我们来说非常有效.主要优点是:
该套件要求我们在对等服务中进行数据设置,这意味着测试通常需要更多时间来编写.我们尽可能使用REST客户端在对等服务中进行数据设置.
此套件中的测试通常需要更长时间才能编写,因此我们将大部分内容放在第1套中.据说这套套件仍有明显价值,因为我们在套件1中的模拟可能与真实服务不同.
chx*_*007 25
Frisby是一个基于node.js和Jasmine构建的REST API测试框架,它使测试API端点变得简单,快速和有趣. http://frisbyjs.com
例:
var frisby = require('../lib/frisby');
var URL = 'http://localhost:3000/';
var URL_AUTH = 'http://username:password@localhost:3000/';
frisby.globalSetup({ // globalSetup is for ALL requests
request: {
headers: { 'X-Auth-Token': 'fa8426a0-8eaf-4d22-8e13-7c1b16a9370c' }
}
});
frisby.create('GET user johndoe')
.get(URL + '/users/3.json')
.expectStatus(200)
.expectJSONTypes({
id: Number,
username: String,
is_admin: Boolean
})
.expectJSON({
id: 3,
username: 'johndoe',
is_admin: false
})
// 'afterJSON' automatically parses response body as JSON and passes it as an argument
.afterJSON(function(user) {
// You can use any normal jasmine-style assertions here
expect(1+1).toEqual(2);
// Use data from previous result in next test
frisby.create('Update user')
.put(URL_AUTH + '/users/' + user.id + '.json', {tags: ['jasmine', 'bdd']})
.expectStatus(200)
.toss();
})
.toss();
Run Code Online (Sandbox Code Playgroud)
Bob*_*Gee 20
由于这个原因,我与我的一位同事合作启动了PyRestTest框架:https: //github.com/svanoort/pyresttest
虽然您可以使用Python中的测试,但正常的测试格式是YAML.
基本REST应用程序的示例测试套件 - 验证API是否正确响应,检查HTTP状态代码,但您也可以检查响应主体:
---
- config:
- testset: "Tests using test app"
- test: # create entity
- name: "Basic get"
- url: "/api/person/"
- test: # create entity
- name: "Get single person"
- url: "/api/person/1/"
- test: # create entity
- name: "Get single person"
- url: "/api/person/1/"
- method: 'DELETE'
- test: # create entity by PUT
- name: "Create/update person"
- url: "/api/person/1/"
- method: "PUT"
- body: '{"first_name": "Gaius","id": 1,"last_name": "Baltar","login": "gbaltar"}'
- headers: {'Content-Type': 'application/json'}
- test: # create entity by POST
- name: "Create person"
- url: "/api/person/"
- method: "POST"
- body: '{"first_name": "Willim","last_name": "Adama","login": "theadmiral"}'
- headers: {Content-Type: application/json}
Run Code Online (Sandbox Code Playgroud)
我使用SOAP UI进行功能和自动化测试。SOAP UI 允许您单击按钮即可运行测试。还有一个由 Ted Young 创建的Spring 控制器测试页面。我使用本文在我们的应用程序中创建 Rest 单元测试。
| 归档时间: |
|
| 查看次数: |
134604 次 |
| 最近记录: |