DRY或DAMP-在API自动化测试脚本中,哪一个有效? [英] DRY or DAMP - Which one is efficient in API automation test scripts?
问题描述
我目前正在编写REST API自动化测试脚本.正如大多数研究文章所建议的那样,我们应该编写 DAMP(描述性和有意义的短语)测试以提高可读性.但是,我觉得我的测试中有很多重复的代码,为了删除重复的代码,我最终得到了倾向于依赖测试的" DRY "(不要重复自己)代码. .因此,我对使用哪种方法感到有些困惑?如果有人可以给我一些建议,我将不胜感激.
I am currently writing REST API automation test scripts. As most of the research article suggests that we should write DAMP (Descriptive And Meaningful Phrases) tests that promote readability. However, I feel that there are a lot of duplicate codes in my tests and in an attempt to remove the duplicates I end up with 'DRY' (Don't repeat yourself) code which tends to dependency tests. So I am a bit confused about which approach to use? I would really appreciate it If anyone can give me some suggestions on this?
推荐答案
我的建议是:
- 尽可能重用文件中的有效负载(JSON或XML) 设置
- 登录流应可重复使用
- 请勿将对不同端点的API请求合并到可重复使用的
Scenario
中
- 即使对于同一端点,对于非常不同的有效负载(例如边界/错误条件),也请为每个端点使用单独的
Scenario
- 使用
Scenario Outlines
进行数据驱动的测试
Authorization
标头的- re-use payloads (JSON or XML) from files where possible
- sign-in flows that set an
Authorization
header should be re-usable - do not combine API requests to different end-points into a re-usable
Scenario
- even for the same end-point, for very different payloads (e.g. boundary / error conditions) use a separate
Scenario
for each - use
Scenario Outlines
for data-driven tests
另外,请参考此答案以获取不执行操作的好示例: https://stackoverflow.com/a/54126724/143475
Also please refer this answer for a good example of what NOT to do: https://stackoverflow.com/a/54126724/143475
这篇关于DRY或DAMP-在API自动化测试脚本中,哪一个有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!