Scenario:模組化定義Fitnesse測試案例的能力和局限

來源:互聯網
上載者:User

標籤:blog   http   java   使用   os   io   strong   for   

首先普及一下概念,什麼是Fitnesse,聽一聽.NET版Cucumber的創始人Aslak Hellesøy談Fitnesse與Cucumber對比:

FIT/Fitnesse和Cucumber都執行進階語言編寫的驗收測試。FIT僅識別HTML,Fitnesse則通過提供Wiki文法來簡化編寫測試的過程。在FIT/Fitnesse當中,所有的測試都以表格的形式呈現。 
FitNesse比Cucumber的優勢在於Wiki支援。

原文連結:http://www.infoq.com/cn/news/2009/11/interview-cucumber-for-dotnet

《需求規格實例化》中關於Fitneese的描述:

FitNesse套件(活文檔)覆蓋的所有功能,通過了完整的系統測試和使用者驗收測試,在生產環境上線時也沒有發現任何缺陷。系統測試時發現了幾個核心計算群組件以外的錯誤。業務人員之所以覺得使用者驗收測試非常好,是因為出現計算錯誤時,我們都非常確定根本問題是在計算代碼的上遊。使用了FitNesse後,很容易診斷出缺陷的根源,從而可以更加利落快速地交付到生產環境中。

原文連結:http://www.douban.com/group/topic/35316487/

1.Scenario是什麼

Fitneese的SliM UserGuide中介紹了 Scenario

原文是這麼介紹Scenario的:

A Scenario table is a table that can be called from other tables; namely Script Table and Decision Table.

The format of a Scenario table is the same as the format of a Script Table, but with a few differences. You can see a Scenario table in action here.

Scenario是一種Table,可以被Script Table 和 Decision Table調用。

由此很多人都對Scenario報了很大的期望,希望能用Scenario模組化封裝測試步驟。

2.Scenario能力展示

下面是我結合Script樣本和Scenario樣本寫的一個Scenario示範用例:

wiki文本:

?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 !define TEST_SYSTEM {slim}!path classes |import||fitnesse.slim.test| !4 定義scenario checkLogin: 登入並檢查結果| scenario | checkLogin | u || p || ensure || logged || @{ensure} | login with username | @{u} | and password | @{p} || check @{logged} | login message | @{u} logged in. || show | number of login attempts | !4 建立script執行個體,後面調用scenario都是針對這個執行個體| script | login dialog driver | Bob | xyzzy | !4 Invoking a scenario from a !-DecisionTable-!| checkLogin || u | p | ensure | logged || Bob | xyzzy | ensure |  || Bob | zzyxx | reject | not || Cat | xyzzy | reject | not | !4 Invoking a scenario from a !-ScriptTable-!| script || checkLogin | Bob || zzyxx || reject || not || checkLogin | Bob || xyzzy || ensure ||  | !4 script原樣本| script | login dialog driver | Bob | xyzzy || login with username | Bob | and password | xyzzy || check | login message | Bob logged in. || reject | login with username | Bob | and password | bad password || check | login message | Bob not logged in. || check not | login message | Bob logged in. || ensure | login with username | Bob | and password | xyzzy || note | this is a comment || show | number of login attempts || $symbol= | login message | The fixture for this table is:{{{public class LoginDialogDriver {  private String userName;  private String password;  private String message;  private int loginAttempts;   public LoginDialogDriver(String userName, String password) {    this.userName = userName;    this.password = password;  }   public boolean loginWithUsernameAndPassword(String userName, String password) {    loginAttempts++;    boolean result = this.userName.equals(userName) && this.password.equals(password);    if (result)      message = String.format("%s logged in.", this.userName);    else      message = String.format("%s not logged in.", this.userName);    return result;  }   public String loginMessage() {    return message;  }   public int numberOfLoginAttempts() {    return loginAttempts;  }} }}}

測試案例頁面:

點擊Test執行後:

展開DecisionTable調用Scenario的測試結果:

展開ScriptTable調用Scenario的測試結果:

至此,我們看到Scenario可以把Script步驟封裝起來,取個模組名,然後使用DecisionTable或ScriptTable調用。

3.Scenario的局限

請注意調用Scenario前的這一行:

目的是在調用Scenario前先建立好Script執行個體。

如果去掉這一句,再執行,是這樣的結果:

再嘗試一下,把建立Script執行個體的語句塞到Scenario中:

?
123456 !4 定義scenario checkLogin: 登入並檢查結果| scenario | checkLogin | u || p || ensure || logged || script | login dialog driver | Bob | xyzzy |   <--這是新加的建立Script執行個體的語句| @{ensure} | login with username | @{u} | and password | @{p} || check @{logged} | login message | @{u} logged in. || show | number of login attempts |

儲存後執行測試:

4.不滿意怎麼辦?

我還想使用Scenario封裝TableTable,比如RestFixture定義的TableTable, 
國外最著名的軟體開發問答網站stackoverflow.com也在問: 
Can I make a scenario of RestFixture table in fitnesse?, or is there another way to make reusable components?

我準備修改Fitneese代碼,使得Scenario能直接封裝ScriptTable和TableTable,請關注後續部落格……

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.