JMeter:使用 CSV 数据集配置将 CSV 文件内容读入 JUnit 测试用例程序 [英] JMeter: Read CSV file contents into JUnit testcase program using CSV Data Set Config

查看:19
本文介绍了JMeter:使用 CSV 数据集配置将 CSV 文件内容读入 JUnit 测试用例程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 JMeter 的 CSV 数据集配置中提到的 CSV 文件中的数据用于我的 JUnit 测试用例程序,并将该数据传递给测试方法.

I want to use data from CSV file mentioned in CSV Data Set Config of JMeter into my JUnit testcase program and pass that data to test method.

我知道如何从 HTTP 请求的 CSV 数据集配置中获取数据,但找不到有关 JUnit 请求的任何帮助.

I know how to get data from CSV Data Set Config for HTTP Request but couldn't find any help for JUnit Request.

我的测试方法是:

public void test() throws IOException{

        try {
            CheckUser(UserId);//I want to get this UserId from CSV file mentioned in CSV Data Set Config of JMeter
        }catch (Exception e) {
            e.printStackTrace();
            fail();  
        }
}

我是 JUnit 和 JMeter 的新手.对此的任何帮助将不胜感激.谢谢.

I am new to JUnit and JMeter. Any help on this would be greatly appreciated. Thanks.

推荐答案

最后我找到了解决方案:

Finally I found solution using:

JUnitSampler junitSampler=new JUnitSampler();String UserId=junitSampler.getThreadContext().getVariables().get("userId");

现在我的 JUnit 测试用例程序正在接受来自 CSV 数据集配置中提到的 CSV 文件的 UserId.

Now my JUnit testcase program is accepting UserId from CSV file mentioned in CSV Data Set Config.

感谢 PMD UBIK-INGENIERIE 和 Dmitri T 的帮助.

Thanks PMD UBIK-INGENIERIE and Dmitri T for your help.

这篇关于JMeter:使用 CSV 数据集配置将 CSV 文件内容读入 JUnit 测试用例程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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