在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?

查看:195
本文介绍了在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 lines个数据,我想创建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天全站免登陆