将 csv 值存储到 jmeter 中的 hashmap

store csv values to hashmap in jmeter

我想将 csv 值存储到哈希图中。假设我的列名是 csv 中的 errorcode 和 errormessage,任何人都可以帮助我提供示例代码,因为我仍然坚持使用相同的示例代码。我尝试使用 java 来放置它,但我无法读取这些值。

您可以通过 Beanshell Scripting and bsh.shared namespace 点赞

输入值:

Map map = null;    
if (bsh.shared.map == void) {
    map = new HashMap();        
}
else {
    map = bsh.shared.map;        
}
map.put(vars.get("errorcode"),vars.get("errormessage"));
bsh.shared.map = map;

读取值:

Map map = bsh.shared.map;

Iterator iterator = map.entrySet().iterator();

while (iterator.hasNext()) {
        Map.Entry pair = (Map.Entry)iterator.next();
        String errorcode = pair.getKey();
        String errormessage = pair.getValue();
        //do what you need to do with the values from the HashMap            
}

有关 JMeter 中 Beanshell 脚本的全面信息,请参阅 How to use BeanShell: JMeter's favorite built-in component 指南