在 Robot Framework 中,如何通过为文本文件中的每一行数据创建单独的测试用例来执行数据驱动测试? [英] In Robot Framework, how to perform data-driven testing by creating a separate test case for each line of data in a text file?

查看:16
本文介绍了在 Robot Framework 中,如何通过为文本文件中的每一行数据创建单独的测试用例来执行数据驱动测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Robot Framework中,我们可以使用测试模板来执行数据驱动测试.但是,在这种方法中,测试用例的数量是固定的.我们无法即时添加新的测试用例.

In Robot Framework, we can use Test Template to perform data-driven testing. However, in this method, the number of test cases are fixed. We are not able to add new test cases on-the-fly.

假设我有一个 CSV 文本文件,data.txt:

Let's say I have a CSV text file, data.txt:

data-1a, data-1b, data-1c
data-2a, data-2b, data-2c
....
data-Na, data-Nb, data-Nc

CSV 文件中的行数会不时改变.

The number of lines in the CSV file will change from time to time.

在我的 Robot Framework 测试用例文件中,我将读取这个 CSV 文件.假设该文件中有 N 行 数据,我想创建 N 个测试用例,每个测试用例都使用该文件中的 1 行数据作为参数.

In my Robot Framework test case file, I will read this CSV file. Let's say there are N lines of data in that file, I would like to create N test cases, each using 1 line of data from that file as argument.

是否可以在 Robot Framework 中做到这一点?

Is it possible to do this in Robot Framework?

推荐答案

没有办法直接做你想做的事.您可以做的是编写一个脚本来读取您的数据文件并根据该数据自动生成机器人测试套件.您用于运行测试的脚本可以先运行此其他脚本以创建测试文件,然后再运行它.

There is no way to directly do what you want. What you could do instead is write a script that reads your data file and auto-generates a robot test suite based on that data. The script that you use to run your tests could first run this other script to create the test file before running it.

您也可以通过套件设置创建测试套件,但我认为我不建议这样做,因为我认为没有任何好处,而且它会使您的套件更加复杂.

You could also create the test suite via a suite setup, though I don't think I recommend doing it that way, as I don't think there's anything to gain and it makes your suite more complex.

这篇关于在 Robot Framework 中,如何通过为文本文件中的每一行数据创建单独的测试用例来执行数据驱动测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆