如果示例有太多列,每一行都会太长而难以阅读!

If examples has too many columns ,every row will be too long to read!

如果例子有太多的列,每一行都会太长而无法阅读!

Feature:

  Background:

  Scenario Outline:
    * match '<msg>' == <prefix> + ',' + '<end>'
    Examples:
      | prefix | end   | msg         |
      | hello  | mike  | hello,mike  |
      | hello  | jerry | hello,jerry |

难道是这样的:

Feature:

  Background:
    Examples:
    | prefix |
    | hello  |

  Scenario Outline:
    * match '<msg>' == <prefix> + ',' + '<end>'
    Examples:
      | end   | msg         |
      | mike  | hello,mike  |
      | jerry | hello,jerry |

我想把例子分成几个部分,或者在Outline.What之前设置一个base examples,我应该怎么做?

空手道在其最新版本 0.9.X 中以许多不同的方式解决了这个问题,让我们看看

  1. 如您所问,我们可以在空手道中使用 tableScenario Outline: 之前定义 Examples: 表格,
Feature: my feature
  Background: BG
    * table myExample
      | prefix | end   | msg         |
      | 'hello'  | 'mike'  | 'hello,mike'  |
      | 'hello'  | 'jerry' | 'hello,jerry' |

  Scenario Outline: SOW
    * match '<msg>' == '<prefix>' + ',' + '<end>'
    Examples:
    | myExample |

可以将相同的内容保存在另一个功能文件中并在此功能文件中读取它,但不要复杂化,因为我们在下面还有一些其他解决方案..

2.karate 将所有这些 tableExamples: 视为 JSON 的

的数组

通常你上面的例子将被表示为,

[
  {
    "prefix": "hello",
    "end": "mike",
    "msg": "hello,mike"
  },
  {
    "prefix": "hello",
    "end": "jerry",
    "msg": "hello,jerry"
  }
]

因此空手道允许您使用空手道的 dynamic scenario outline feature

JSONcsv 格式定义这些 Examples

如果您觉得您的示例太大而无法容纳在您的功能文件中,请将其保存在 csv 文件中并在您的 Examples

中阅读
Feature: my feature
  Background: BG
    * def myExample = read("myExample.csv")

  Scenario Outline: SOW
    * match '<msg>' == '<prefix>' + ',' + '<end>'
    Examples:
    | myExample |

这同样适用于 JSON,以 JSON 数组形式提供数据。