2016-12-02 81 views
0

我在尋找可以構建更靈活場景的機制。小黃瓜場景的靈活性。

例如,對於在數據庫中記錄測試的存在,這兩個非常相似的場景:

Scenario Outline: Testing query with 1 attribute with these 2 record in and another 2 out of result 
    Given I'm connected to <db> database 
    When I select <query> from database 
    Then Result should contain fields: 
    | <row> | 
    | <yes1> | 
    | <yes2> | 
    And Result should not contain fields: 
    | <row> | 
    | <no1> | 
    | <no2> | 

    Examples: 
    | db | row | yes1 | yes2 | no1 | no2 | query               | 
    | 1 | model | 1013 | 1006 | 1012 | 1007 | "SELECT model FROM pc WHERE speed >= 3.0;"      | 
    | 1 | maker | E | A | C | H | "SELECT maker FROM product NATURAL JOIN laptop WHERE hd >= 100;" | 

Scenario Outline: Testing query with 2 attributes with these 2 record in and another 2 out of result 
    Given I'm connected to <db> database 
    When I select <query> from database 
    Then Result should contain fields: 
    | <rowA> | <rowB> | 
    | <yes1A> | <yes1B> | 
    | <yes2A> | <yes2B> | 
    And Result should not contain fields: 
    | <rowA> | <rowB> | 
    | <no1A> | <no1B> | 
    | <no2A> | <no2B> | 
    Examples: 
    | db | rowA | rowB | yes1A | yes1B | yes2A | yes2B | no1A | no1B | no2A | no2B | query        | 
    | 1 | model | price | 1004 | 649 | 2007 | 1429 | 2004 | 1150 | 3007 | 200 | "SELECT model,price FROM product" | 
    | 2 | name | country | Yamato | Japan | North | USA | Repulse | Brit | Cal | USA | "SELECT name, country FROM clases" | 

我希望能夠寫帶屬性的一般頭號場景。如果測試行的數量不能確定,那將會很好。

我的夢想是寫只有一個一般情況下

Testing query with N attribute with these M record in and another L out of result 

如何做到這一點的小黃瓜?是否可以用任何黑客?

回答

4

簡短的回答是,不是,小黃瓜不是靈活性,小黃瓜是關於具體的例子。具體例子是除了靈活性之外的所有東西

長的回答是:

你所描述小黃瓜的使用作爲測試工具。然而,小黃瓜的目的不是爲了測試。 Gherkin的目的是促進發展和需要特定行爲的利益相關者之間的溝通。

如果你想測試一些東西,還有其他工具可以支持你想要的東西。任何測試框架都可以使用。我個人的選擇是JUnit,因爲我主要使用Java。

決定工具的試金石是誰,誰必須能夠理解這一點?

如果答案是非技術人員,我可能會用非常具體的例子使用小黃瓜。具體的例子很可能不會比較數據庫中的東西。具體的例子傾向於描述系統的外部可觀察行爲。

如果答案是開發者,那麼我可能會使用一個測試框架,在那裏我可以使用一種編程語言。這將允許您要求的靈活性。

就你而言,你需要一種編程語言。小黃瓜和黃瓜不適合您的情況。

2

您可以在沒有任何黑客行爲的情況下做到這一點,但我不認爲您希望這樣做,至少不需要單一行中的整個場景。
你會想要遵循BDD結構,否則爲什麼要使用BDD?

你應該有,並按照如下的結構:

Given 
When 
Then 

您需要拆分並具有初始上下文,動作(S)和結果(S)之間的界限。它會是一個不好的做法,不這些之間有一個限制。

另請注意,清晰的定界會增加可重用性,可讀性並且在調試過程中也有很大幫助。

請做一個關於BDD的含義及其如何幫助的研究,如果您有一個BDD最佳實踐清單,也可能有助於代碼審查自動化方案,可能會有所幫助。