Oop 小黄瓜中情景的灵活性。

Oop 小黄瓜中情景的灵活性。,oop,bdd,behat,gherkin,non-repetitive,Oop,Bdd,Behat,Gherkin,Non Repetitive,我正在寻找能够构建更灵活场景的机制 例如,对于测试数据库中是否存在记录的这两个非常相似的场景: 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

我正在寻找能够构建更灵活场景的机制

例如,对于测试数据库中是否存在记录的这两个非常相似的场景:

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" |

在小黄瓜里怎么做?有没有可能用黑客攻击?

简单的回答是,没有。小黄瓜不是关于灵活性,小黄瓜是关于具体的例子。具体的例子是一切,除了灵活

答案很长:

您正在描述小黄瓜作为测试工具的用法。然而,小黄瓜的目的不是测试东西。小黄瓜的目的是促进发展与想要特定行为的利益相关者之间的沟通

如果您想要测试某些东西,那么还有其他工具可以支持您想要的东西。任何测试框架都是可用的。我个人的选择是JUnit,因为我主要使用Java

决定工具的试金石是,谁必须能够理解这一点

如果答案是非技术性的,我可能会用小黄瓜和非常具体的例子。具体的例子很可能不是比较数据库中的东西。具体的例子往往描述系统的外部、可观察的行为

如果答案是开发人员,那么我可能会使用一个可以访问编程语言的测试框架。这将允许您要求的灵活性


在您的情况下,您需要一种编程语言。小黄瓜和黄瓜在你的情况下不是合适的工具。

你可以不用任何技巧就完成它,但我认为你不想,至少不想在一行中完成整个场景。 您需要遵循BDD结构,否则为什么要使用BDD

您应该拥有并遵循如下结构:

Given
When
Then
您需要在初始上下文、操作和结果之间进行分割和划分。在这些之间没有限制将是一种不好的做法

还请注意,清晰的定界将提高可重用性、可读性,并对调试有很大帮助

请研究BDD的含义及其帮助方式,如果您有BDD最佳实践的检查表,也可以帮助您对自动化场景进行代码审查,这可能会有所帮助

Given
When
Then