iT邦幫忙

2024 iThome 鐵人賽

DAY 16
0
Software Development

開發都來不及了還做什麼測試系列 第 16

Day16. API 測試 - 以Trello API為例

  • 分享至 

  • xImage
  •  
  1. 會在Postman建立一個Project
  2. 而這個API Testing Project是用來測試Trello board creation的
  • Create Board
  • Create a list inside this board
  • 在每個List中建立Card
  • 新增Checklist 等資訊在card 內

自動化建立這些

Trello API

https://developer.atlassian.com/cloud/trello/rest/api-group-actions/

https://ithelp.ithome.com.tw/upload/images/20240914/20108631lB6LLf4eNZ.png

Create Board in Trello APIs

https://ithelp.ithome.com.tw/upload/images/20240914/20108631L7ZNWDhSpD.png

Type: POST
URL: https://api.trello.com/1/boards/
Params:

  • name = Bootcamp_test
  • key = <your api key>
  • token = <your token>

https://developer.atlassian.com/cloud/trello/guides/power-ups/managing-power-ups/#adding-a-new-custom-power-up

Key 和 token可以從以下網站取得
https://trello.com/power-ups/admin

https://ithelp.ithome.com.tw/upload/images/20240914/20108631RwH4uRYhZZ.png

New
https://ithelp.ithome.com.tw/upload/images/20240914/20108631YNMOmZSrJN.png

Create
https://ithelp.ithome.com.tw/upload/images/20240914/20108631Szezl7aul8.png

Generate a new API key

只有14天的有效期
https://ithelp.ithome.com.tw/upload/images/20240914/20108631t8VOFZ9kqA.png

Generate Token

https://ithelp.ithome.com.tw/upload/images/20240914/20108631mFrUf4G8At.png

https://ithelp.ithome.com.tw/upload/images/20240914/20108631f30IDCHSxM.png

https://ithelp.ithome.com.tw/upload/images/20240914/20108631VppZ6cOaPe.png

Delete Board

URL: https://api.trello.com/1/boards/

https://ithelp.ithome.com.tw/upload/images/20240914/20108631If3vKorEHt.png

Set key an token as variable

https://ithelp.ithome.com.tw/upload/images/20240914/20108631kqqcKQZN0H.png

建立測試排程

寫test cases

Category Requests Dependency Priority
Board Create board None Critical
Update board Create board Hight
Read board Create board Medium
Delete board Create board, Update board Low
List Create list Create board Critical
Update list Create list Hight
Get list Create list Medium
Delete list Create list, Update list Low
Card Create card Create list Critical
Update card Create card Hight
Get card Create card Medium
Delete card Create card , Update card Low
Checklist Create checklist Create card Low
Update checklist Create checklist Low
Get checklist Create checklist Low
Delete checklist Create checklist, Update checklist Low

Test Execution Schedule

Order
1 Create board
2 Create list
3 Create card
4 Update board
5 Update list
6 Update ard
7 Read board
8 Read list
9 Read card
10 Create checklist
11 Update checklist
12 Get checklist
13 Delete checklist
14 Delete card
15 Delete list
16 Delete board

https://ithelp.ithome.com.tw/upload/images/20240914/20108631iAOxYPosTj.png

Delete change to use board_id variable
https://ithelp.ithome.com.tw/upload/images/20240914/20108631i8Puqs45ZQ.png

Run collection
https://ithelp.ithome.com.tw/upload/images/20240914/20108631tdsv4VFbIX.png

https://ithelp.ithome.com.tw/upload/images/20240914/20108631u8iv4jk7nV.png

新增測項

Create

var jsonData = pm.response.json()

// pm.globals.set("variable_key", "variable_value")

pm.globals.set("board_id", jsonData.id)

pm.test("Board created successfully", function() {
    pm.response.to.have.status(200)
} )

pm.test("Reasonable response time", function (){
    pm.expect(pm.response.responseTime).to.be.below(3000)
})

pm.test("Correct board name", function() {
    var jsonData = pm.response.json()
    pm.expect(jsonData.name).to.eql("Bootcamp_test1")
})

Delete

pm.test("Board deleted successfully", function() {
    pm.response.to.have.status(200)
} )

pm.test("Reasonable response time", function (){
    pm.expect(pm.response.responseTime).to.be.below(3000)
})

https://ithelp.ithome.com.tw/upload/images/20240914/20108631aXFikqlCGm.png

Common test cases

直接點選資料夾 -> Scripts -> Post-response

https://ithelp.ithome.com.tw/upload/images/20240914/201086310On8hwujTC.png

本文章同步發布於個人blogger


上一篇
Day15. 使用 Postman 測試 API
下一篇
Day17. Performance Testing - 1
系列文
開發都來不及了還做什麼測試30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言