目錄表

Robotframework的Best Practice/Do與Don't

Introduction

幾年前剛開始用Robotframework時,並沒有明確的規範大家的coding style;但隨著開發人員的增加,不管是測試的分類、測試涵蓋規範、測試或關鍵字的命名,都隨著時間慢慢歪掉。為了:

  1. 測試利於維護;
  2. 測試容易閱讀;
  3. 容易建立user story與測試的連結。

以上原因,必須建立一些共識。而我認為面對到以下問題:

Naming

節錄自官方參考文件Robot Best Practice:

這是Robot建議的方式,假如有自己的規範也不一定要使用他們建議的。

Structure

Suite Structure

節錄自官方參考文件:

我認為其它可實踐的:

Test Structure

節錄自官方參考文件:

個人看法:

練習

[TestSuite]
user_management.txt
[TestCase]
Add a user 
     Given User login
     When Interact with add user command
     Then You see the new user
Add an invalid user
     Given User login
     When Interact with add user command 
     And Input an invalid Name
     Then You see a feedback show the name is invalid
Thinking..

  1. 共用的行為該如何放置到Setup或Teardown中? 參考此篇
  2. data-driven方式該如何撰寫? 參考此篇

data-driven可搭配tempalte寫成以下形式:

*** Test Case ***
WebLinks are clickable
     [Template]     WebLink is clickable
     ## link name ##     ## expect content ##
     Home                 home content
     About                about content               
     EMail                email@hotmail.com
     
*** Keyword ***     
WebLink is clickable
     [Arguments]     ${link}     ${expect_content}
     Given I login the system
     When I click ${link}
     Then I can see ${expect_content}

命名以外的Coding Style

Reference

與Coding Style相關的文章

Gherkin Style基本知識