如何从黄瓜外部文件中读取数据,而不是在示例部分提及大量数据?我正在使用Cucumber-jvm

问题描述 投票:1回答:2
@@file_name Feature: Addition

为了避免愚蠢的错误作为一个数学白痴我想要被告知两个数字的总和

场景:添加两个数字

Given I have entered @number1 into the calculator
And I have entered @number2 into the calculator
When I press Add
Then the result should be @total1 on the screen

场景:添加后的乘法

Given the total is @total1
When multiply it with @number3
Then the result should be @total2 on the screen

我有一个xls文件,其列有qazxsw poi qazxsw poi,total1total 2number 1等。

cucumber-jvm cucumber-java
2个回答
2
投票

这样做通常很诱人并且引用外部文件来获取数据,但是,通过这样做,您将完全放松BDD的利益相关者方面之间的通信。

如果它真的像添加这样的2个数字一样简单,您可以使用场景大纲/示例:number 2

否则,问问自己你在这里尝试用Cucumber做什么,因为如果要隐藏Excel文件中的示例,我不确定是否值得添加这一层。我建议你选择一个在适当的场景中实现的例子。对于其他示例,编写常规Junit测试以从文件中读取并从中获取数据并在测试中运行您的代码,方法与步骤定义相同


2
投票

AAARG!看起来数据表(number 3)和例子之间的区别:表格(只与https://github.com/cucumber/cucumber/wiki/Scenario-Outlines一起使用)在这个帖子中完全丢失了。您可以消除对外部电子表格的任何感知需求的方法是将数据表放在要素文件中。通过这种方式,没有任何外部依赖会导致维护头痛;它都在功能文件中,它属于它。

© www.soinside.com 2019 - 2024. All rights reserved.