差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

Both sides previous revision 前次修改
下次修改
前次修改
rf:rf:best_practice [2016/12/04 22:26]
tony [Test Structure]
rf:rf:best_practice [2023/06/25 09:48] (目前版本)
行 36: 行 36:
   * 避免testcase level的變數賦予。   * 避免testcase level的變數賦予。
 個人看法:​ 個人看法:​
-  * 使用Gherkin Style後,應能達到 1. 行為抽象化避免牽扯底層實作;2. 伴隨驗證行為; 3. 增加可讀性;因為Gherkin Style寫法本身就已經避免掉某些don'​t。+  * 使用Gherkin Style後,應能達到 1. 行為抽象化避免牽扯底層實作,只需寫必要表達的部分;2. 必會伴隨驗證行為; 3. 增加可讀性;Gherkin Style寫法本身就已經避免掉某些don'​t。
   * 當Test第一層Keyword夠淺顯易懂後,Test本身應不需特別寫文件的。   * 當Test第一層Keyword夠淺顯易懂後,Test本身應不需特別寫文件的。
 +  * 在寫測試時,常會把相關的assertion放在同一個testcase中,這會因前面的錯而無法得知後面的是否正確。Data-Driven的方式也許可以解決這問題,但在keyword的設計上,就要仔細思考了;另外個方法就是一個測試驗證一個主要目標,但Testsuite的粒度就很重要了,否則會讓測試數量變得非常龐大。
 +  * Gherkin Style的作法會產生大量的新keyword,Robotframework本身提供兩個方法可減少此問題([[http://​robotframework.org/​robotframework/​latest/​RobotFrameworkUserGuide.html#​behavior-driven-style|reference]]): ​
 +     - Ignoring Given/​When/​Then/​And/​But prefixes: 舉例來說,keyword名稱假設為User login,你可以寫成Given User Login,也可以寫成When User Login。
 +     - Embedding data to keywords: 舉例來說,通常都是以參數型式寫成Click Element | ${link},現在也可以寫成Click ${link}。這讓你keyword更像是一個句子。
 === 練習 === === 練習 ===
 <​code>​ <​code>​
行 54: 行 58:
 </​code>​ </​code>​
 Thinking..\\ Thinking..\\
-  - 共用的行為該如何放置到TestSuite中? [[http://​morelia.readthedocs.io/​en/​latest/​gherkin.html|參考此篇]]+  - 共用的行為該如何放置到Setup或Teardown中? [[http://​morelia.readthedocs.io/​en/​latest/​gherkin.html|參考此篇]]
   - data-driven方式該如何撰寫?​ [[https://​blog.codecentric.de/​en/​2009/​11/​givenwhenthen-and-example-tables-using-the-robot-framework/​|參考此篇]]   - data-driven方式該如何撰寫?​ [[https://​blog.codecentric.de/​en/​2009/​11/​givenwhenthen-and-example-tables-using-the-robot-framework/​|參考此篇]]
 +data-driven可搭配tempalte寫成以下形式:​
 +<​code>​
 +*** 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}
 +</​code>​
 +
 ===== 命名以外的Coding Style ===== ===== 命名以外的Coding Style =====
   * 如果會被重複使用的數值,可以透過變數減少Hardcode。   * 如果會被重複使用的數值,可以透過變數減少Hardcode。
行 62: 行 84:
   * 使用polling的方式去等待事件;避免使用sleep方式去等待事件。   * 使用polling的方式去等待事件;避免使用sleep方式去等待事件。
 ===== Reference ===== ===== Reference =====
-  ​* [[http://​www.slideshare.net/​pekkaklarck/​robot-framework-dos-and-donts|Do ant Don'​t]] [[http://​blog.castman.net/​programming/​2016/​07/​28/​robotframework.html|中文介紹]] +==== 與Coding Style相關的文章 ==== 
-  * [[http://​code.google.com/​p/​robotframework/​wiki/​HowToWriteGoodTestCases|How to write good testcaes?]] +  ​* [[http://​www.slideshare.net/​pekkaklarck/​robot-framework-dos-and-donts|Do ant Don'​t]] ​ 
-  * [[http://​www.jollen.org/​blog/​2014/​11/​mokoversity-farm-1.html|BDD]] ​主要看Given/​When/​Then寫法+  * [[http://​blog.castman.net/​programming/​2016/​07/​28/​robotframework.html|中文介紹]] 
 +  * [[http://​code.google.com/​p/​robotframework/​wiki/​HowToWriteGoodTestCases|How to write good testca 
 +es?]] 
 +  * [[https://​www.sitepoint.com/​smelly-cucumbers/​|smelly-cucumbers]] 這篇探討如何寫好Gherkin Style,我認為是keyword精細度的問題吧! 
 +==== Gherkin Style基本知識 ==== 
 +  * [[http://​www.jollen.org/​blog/​2014/​11/​mokoversity-farm-1.html|BDD]] ​
   * [[http://​docs.behat.org/​en/​v2.5/​guides/​1.gherkin.html|Gherkin language]]   * [[http://​docs.behat.org/​en/​v2.5/​guides/​1.gherkin.html|Gherkin language]]
-  * [[https://github.com/cucumber/cucumber/wiki/Given-When-Then|Given-When-Then]]+  * [[http://martinfowler.com/bliki/GivenWhenThen.html|GivenWhenThen]] 
 +  * [[https://sukesh15.gitbooks.io/​cucumber-jvm-test-framework-/​content/​cucumber_-_more_details/​data_driven_testing_using_cucumber.html|data-driven testing using cucumber]]
  
 =====    ===== =====    =====