将汇总报告结果添加到 JMETER 中的数据库中

2022-01-04 00:00:00 database mysql jmeter jmeter-plugins

有什么方法可以将在 JMETER 中测试结束时生成的汇总报告结果添加到数据库中吗?我在数据库中创建了一个表.在这个表中,我想存储汇总结果.我正在使用 Mysql 数据库.我该怎么做?

谢谢.

解决方案

您可以这样做:

  1. 下载 MySQL JDBC 驱动程序 并将其放到 JMeter 安装的/lib 文件夹中
  2. 重新启动 JMeter 以选择 .jar
  3. 将摘要报告侦听器添加到您的测试计划中.
  4. 将其配置为将结果保存到某个文件,即 c:jmeteresults.csv
  5. 将tearDown 线程组添加到您的测试计划
  6. 添加JDBC连接配置并提供:

    • 绑定到池的变量名:任何有意义的东西,即results
    • 数据库 URL:即 jdbc:mysql://localhost:3306/YOUR_DATABASE_NAME_HERE
    • 数据库驱动类:com.mysql.jdbc.Driver
    • 凭据
  7. 添加JDBC Sampler,配置如下:>

    • 变量名:与 JDBC 连接配置中的变量名相匹配的内容,即 results
    • 查询类型:更新语句
    • 查询:将数据本地infile 'c:jmeteresults.csv'加载到表YOUR_TABLE_NAME_HERE中,字段以','结尾,'"'行以' '结尾;

通过这种方式,您将能够自动插入结果.

参考文献:

  • MySQL 加载数据文件
  • 构建数据库测试计划的真正秘诀JMeter
  • 在 JMeter 中调试 JDBC 采样器结果

以防万一,如果您不知道如何使用如下查询为结果创建表:

创建表测试(timeStamp varchar(255),elapsed varchar(255),label varchar(255),responseCode varchar(255),responseMessage varchar(255),threadName varchar(255),dataType varchar(255)),成功 varchar(255),bytes varchar(255),grpThreads varchar(255),allThreads varchar(255),Latency varchar(255));

查看MySQL CREATE TABLE Syntax 文档了解更多信息信息.

Is there any way I can add the summary report results which are generated at the end of the test in JMETER to the database ? I have created a table in in database. In this table I want to store the summary results. I am using Mysql database. How can I do this ?

Thankyou.

解决方案

You can do it as follows:

  1. Download MySQL JDBC Driver and drop it to /lib folder of your JMeter installation
  2. Restart JMeter to pick the .jar up
  3. Add Summary Report listener to your Test Plan.
  4. Configure it to save results to some file, i.e. c:jmeteresults.csv
  5. Add tearDown Thread Group to your Test Plan
  6. Add JDBC Connection Configuration and provide:

    • Variable Name Bound to Pool: anything meaningful, i.e. results
    • Database URL: i.e. jdbc:mysql://localhost:3306/YOUR_DATABASE_NAME_HERE
    • Database Driver Class: com.mysql.jdbc.Driver
    • Credentials
  7. Add JDBC Sampler and configure it as follows:

    • Variable Name: something which matches Variable Name in JDBC Connection Configuration, i.e. results
    • Query Type: Update Statement
    • Query: load data local infile 'c:jmeteresults.csv' into table YOUR_TABLE_NAME_HERE fields terminated by ',' enclosed by '"' lines terminated by ' ';

This way you will be able to get results inserted automatically.

References:

  • MySQL LOAD DATA INFILE
  • The Real Secret to Building a Database Test Plan With JMeter
  • Debugging JDBC Sampler Results in JMeter

Just in case if you don't know how to create a table for results with query like:

create table test (timeStamp varchar(255),elapsed varchar(255),label varchar(255),responseCode varchar(255),responseMessage varchar(255),threadName varchar(255),dataType varchar(255),success varchar(255),bytes varchar(255),grpThreads varchar(255),allThreads varchar(255),Latency varchar(255) );

See MySQL CREATE TABLE Syntax documentation for more information.

相关文章