简体   繁体   English

在多个代码功能测试中使用相同的小黄瓜步骤

[英]Using the same gherkin steps in multiple codeception functional tests

Say I've got a functional test scenario in example1.feature that has a step like 假设我在example1.feature中有一个功能测试场景,其中包含一个步骤

"I have something in the database" “我在数据库中有一些东西”

In my steps folder I've got the implementation of that step in the file example1.php . 在我的steps文件夹中,我已经在example1.php文件中执行了该步骤。

Now say I want to use that same step in example2.feature . 现在说我想在example2.feature中使用相同的步骤。 I know that if I don't implement that step in example2.php , it'll automatically use the implementation from example1.php. 我知道如果我没有在example2.php中实现该步骤,它将自动使用example1.php中的实现。

But is that recommended? 但这是推荐的吗? implementing steps from for one test in the class of another test? 在另一个测试的类中实现一个测试的步骤? It seems like that'd break test group isolation... 看起来好像打破了测试组隔离......

Or should I copy/paste the code into example2.php so that each test has its own implementation of the steps? 或者我应该将代码复制/粘贴到example2.php中,以便每个测试都有自己的步骤实现? Seems very un-dry and a maintenance nightmare... 看起来非常干燥,维护噩梦......

Or is there another recommended way to handle this kind of situation, maybe having all the step classes extend a common class that defines steps to be used in multiple tests? 或者是否有另一种推荐的方法来处理这种情况,也许所有的步骤类都扩展了一个公共类,它定义了在多个测试中使用的步骤?

Is it possible to have two implementations for the same step? 是否可以为同一步骤实现两个实现? In other flavors of Cucumber you will bet an ambiguous step error. 在其他类型的黄瓜,你会打赌一个模糊的步骤错误。 The tool doesn't know which implementation to use. 该工具不知道要使用哪种实现。

If it is possible with two implementations, then I would not worry about which file a step is implemented is. 如果可以实现两个实现,那么我不担心步骤的实现是哪个文件。 I would worry more about having the same implementation in two places. 我更担心在两个地方实现相同的实现。

The reason I would be more worried about two implementations is that there is no good way to know that they don't deviate during maintenance. 我更担心两个实现的原因是没有好的方法可以知道它们在维护期间不会偏离。 If they deviate then you end up in a situation where the same step in Gherkin means two different things. 如果他们偏离,那么你最终会遇到Gherkin中同一步骤意味着两件不同的事情。 That would be bad. 那会很糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM