[英]Codeception, gherkin test, how organize my code?
I followed the official Codeception guide (from their website of course) and I created a simple test written in Gherkin. 我遵循了官方的Codeception指南(当然来自他们的网站),并且创建了一个用小黄瓜编写的简单测试。
With the command codecept gherkin:snippets
command, I printed all methods I must implement. 使用命令
codecept gherkin:snippets
命令,我打印了必须实现的所有方法。 Then I copied these methods to the tests/_support/AcceptanceTester.php
file. 然后,我将这些方法复制到
tests/_support/AcceptanceTester.php
文件。
My question is: today, it's a sample test, but tomorrow, if I must create a lot of acceptance tests, how do I organize my code ? 我的问题是:今天,这是一个示例测试,但是明天,如果我必须创建很多验收测试,该如何组织代码?
I suppose I must write each main scenario in several PHP files. 我想我必须在几个PHP文件中编写每个主要方案。 But, where I can save these files?
但是,在哪里可以保存这些文件? How do I link these files together?
如何将这些文件链接在一起?
Let's say I must create two big scenarios of acceptance tests. 假设我必须创建两个主要的验收测试方案。 The
Scenario A
can be run alone, but the Scenario B
must be run after the Scenario A
. Scenario A
可以单独运行,但是Scenario B
必须在Scenario A
之后运行。
Where do I need to create the files A and B? 我需要在哪里创建文件A和B? And, how can I "say" to Codeception I can run the
Scenario B
only after the A
has been executed? 而且,我怎么能“说”给我Codeception可以运行
Scenario B
的唯一后A
已被执行?
Sorry for my English, I hope my questions are clear. 对不起,我的英语,希望我的问题清楚。
You can tell Codeception that a scenario depends on something else by using @depends
followed by the test signature. 您可以通过使用
@depends
和测试签名来告诉Codeception一个方案还取决于其他情况。 According to the documentation : 根据文档 :
And what is more interesting, you can make tests to depend on feature scenarios.
更有趣的是,您可以根据功能场景进行测试。 Let's say we have
login.feature
file with “Log regular user” scenario in it.假设我们有一个
login.feature
文件,其中包含“登录普通用户”方案。 In this case you can specify that every test which requires login to pass to depend on “Log regular user” scenario:在这种情况下,您可以指定每个需要登录通过的测试都取决于“记录常规用户”方案:
@depends login:Log regular user
Inside
@depends
block you should use test signature.在
@depends
块中,您应该使用测试签名。 Execute your feature withdry-run
to see signatures for all scenarios in it.通过
dry-run
执行功能,以查看其中所有场景的签名。 By marking tests with@depends
you ensure that this test won't be executed before the test it depends on.通过使用
@depends
标记测试,可以确保不会在依赖该测试之前执行该测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.