5

I am running into a bit of a conundrum. We have an antiquated system that I am writing Behat tests for. It works great for the most part. But I have noticed an issue where the Behat tests will fail if the data I am testing against the current environment was meant for/pulled from a different environment.

For example, if I test a search by phone function in QA and expect it to return a specific entity id I cannot use that same phone number and entity id to test in RC or Live. So I would like a manageable way to maintain the testing data for each environment in Behat.

A couple thoughts have been throw around here such as putting the data into the profile (highly undesireable) or creating CSV files for each feature. I also am thinking about building all the data-specific scenarios using tables or scenario outlines and having an environment column that will be used to check against the current environment and skip when the row is not for the current environment. Maybe using a Background or some other hook to help out with this.

Does anyone know of a good way or best practice for dealing with multiple environments with different data sets in each with Behat?

4

1 回答 1

5

根据 KNP 实验室的人员在他们的一次培训中的说法,最佳实践是创建必要的数据,以使场景作为 Given 或 Background 的一部分成功,因此您最终会得到一个“鉴于我有 7 个电话号码”的步骤并且步骤定义插入了七个电话号码,在该场景的其余部分中可以依赖这些电话号码。

当然,如果您希望针对生产站点运行测试,这通常是不可行的,而且我所看到的策略确实会因所涉及的特定数据量以及生产数据的易变性而异。

由于最佳实践还规定功能文件应以功能受益人可以合理预期理解的方式描述应用程序行为,因此在功能文件中暴露环境条件数据的任何内容都不太可能是最佳方法。目标功能用户可能不知道不同的环境。

如果生产数据足够稳定,可以编写测试,我会考虑在 behat.yml 中设置一个参数或配置文件,可用于在运行时指示环境并编写自定义步骤定义。自定义步骤定义可以在一种情况下提供已知的生产值,并在其他情况下插入这些值。Gherkin 仍然看起来像“鉴于我有 7 个电话号码”,因此该功能将专注于业务价值和对用户的好处,而不是测试环境。

于 2013-07-13T16:17:04.353 回答