JMeter: Read CSV file contents into JUnit testcase program using CSV Data Set Config

前端 未结 3 1595
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 19:42

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.

I know how to get data from

相关标签:
3条回答
  • 2021-01-26 20:06

    The answer by PMD UBIK-INGENIERIE is correct and should work.

    Make sure that your userId variable is set and is not null via i.e. Debug Sampler and View Results Tree listener combination.

    Also remember that JMeter Variables scope is limited to current thread group only, if you want to use values from another thread group you need to convert JMeter Variables to JMeter Properties which have global scope. See Knit One Pearl Two: How to Use Variables in Different Thread Groups for more details.

    You can refer a property as follows:

    JMeterContextService.getContext().getCurrentSampler().getPropertyAsString("userId") 
    
    0 讨论(0)
  • 2021-01-26 20:09

    Finally I found solution using:

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

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

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

    0 讨论(0)
  • 2021-01-26 20:24

    You can try using:

     JMeterContextService.getContext().getVariables().get("varName") 
    

    see:

    • https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html#getVariables()

    • https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html

    0 讨论(0)
提交回复
热议问题