第一個測試用例
Robot Framework 測試用例使用一種簡單表格語法。下表含有兩個樣例:
· 用戶可以創建賬戶并登入
· 用戶使用錯誤密碼無法登入
Test Case |
Action |
Argument |
Argument |
---|---|---|---|
User can create an account and log in |
Create Valid User |
fred |
P4ssw0rd |
Attempt to Login with Credentials |
fred |
P4ssw0rd |
|
Status Should Be |
Logged In |
||
User cannot log in with bad password |
Create Valid User |
betty |
P4ssw0rd |
Attempt to Login with Credentials |
betty |
wrong |
|
Status Should Be |
Access Denied |
注意 這些測試比起自動測試用例更像用英語手工寫的測試。Robot Framework 使用關鍵詞驅動的方式,支持用自然語言來編寫可以抓住動作和期望值的本質的測試。測試用例由關鍵詞(通常在第二列)和它們可能的參數組成。
高級別測試用例
測試用例也可以通過使用不攜帶參數的高級別關鍵詞來創建。這種風格允許使用完全的自由文本以便于進行交流,即使是和非技術人員或者其他利益相關者。T Robot Framework 不強制使用任何風格來編寫測試用例,它可以用于行為驅動開發behavior-driven development (BDD)推薦的given-when-then 格式的樣例,如下所示。
Test Case |
Steps |
---|---|
User can change password |
Given a user has a valid account |
when she changes her password |
|
then she can log in with the new password |
|
and she cannot use the old password anymore |
這種測試用例或者用戶故事風格的測試用例的類型很適合用于acceptance test-driven development (ATDD). 在 ATDD 中接收測試在實現實際產品特性前編寫并且他們反映了需求。
數據驅動測試用例
通常部分測試用例除了部分不同的輸入或者輸出數據外都.在這些情況下數據驅動,如下面六個測試用例,允許在不復制工作流的情況下改變測試數據 。
Test Case |
Action |
Password |
Expected error message |
---|---|---|---|
Too short password |
Creating user with invalid password should fail |
abCD5 |
${PWD INVALID LENGTH} |
Too long password |
Creating user with invalid password should fail |
abCD567890123 |
${PWD INVALID LENGTH} |
Password without lowercase letters |
Creating user with invalid password should fail |
123DEFG |
${PWD INVALID CONTENT} |
Password without capital letters |
Creating user with invalid password should fail |
abcd56789 |
${PWD INVALID CONTENT} |
Password without numbers |
Creating user with invalid password should fail |
AbCdEfGh |
${PWD INVALID CONTENT} |
Password with special characters |
Creating user with invalid password should fail |
abCD56+ |
${PWD INVALID CONTENT} |
原文轉自:http://www.anti-gravitydesign.com