黄瓜:场景中的使用文件

时间:2013-12-18 15:48:33

标签: java cucumber integration-testing

我有以下情况:

Feature: Some feature
   Scenario: Test feature
     Given login as test_user
     When test_user submits changes with content:
        """
        Very long text
        """
     Then content is saved

主要目标是将“非常长的文本”移动到某个文件或类似的内容,并避免在定义的场景中重复此文本。

1 个答案:

答案 0 :(得分:3)

我只看到一个解决方案(这个解决方案不太好,但可以作为替代方案):

Feature: Some feature
   Scenario: Test feature
     Given login as test_user
     When test_user submits changes with content very_long_text.txt            
     Then content is saved

将very_long_text.txt放入项目测试资源中。可以创建单独的文件夹来保存所有黄瓜资源。例如:src / test / resources / cucumber

创建读取此资源内容的Utility类:

public static String getText(String fileName){
    IOUtils.toString("cucumber" + fileName);
}

以这种方式使用文件内容。为了不在代码中重复消息

相关问题