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

查看:264
本文介绍了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.

我知道如何从CSV数据集配置中获取HTTP请求的数据,但是找不到有关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");

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天全站免登陆