【问题标题】:If examples has too many columns ,every row will be too long to read!如果示例的列太多,每一行都会太长,无法阅读!
【发布时间】:2019-05-14 16:49:22
【问题描述】:

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

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 |

我想把例子分成几个部分,或者在大纲之前设置一个基础例子,我该怎么办?

【问题讨论】:

    标签: karate


    【解决方案1】:

    空手道在其最新版本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"
      }
    ]
    

    所以 karate 允许您使用 karate 的 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 数组的形式提供数据。

    【讨论】:

      猜你喜欢
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 2016-08-09
      相关资源
      最近更新 更多