【问题标题】:JMeter: Recallable BeanShell Assertion?JMeter:可调用的 BeanShell 断言?
【发布时间】:2016-03-02 02:06:49
【问题描述】:

我正在执行基本 CRUD 功能的 API 测试。对于每个线程组中每种记录类型的创建,我使用的是为每个线程组定制的相同 BeanShell 断言模板。

import org.apache.jmeter.services.FileServer;

if (ResponseCode != null && ResponseCode.equals("200") == true) {
SampleResult.setResponseOK();  
}
else if (!ResponseCode.equals ("200") == true ) { 
    Failure = true;
    FailureMessage ="Creation of a new {insert record type} record failed. Response code " + ResponseCode + "." ; // displays in Results Tree
    print ("Creation of a new {insert record type} record failed: Response code  " + ResponseCode + ".");   // goes to stdout
    log.warn("Creation of a new {insert record type} record failed: Response code " + ResponseCode); // this goes to the JMeter log file

// Static elements or calculations
part1 = "\n FAILED TO CREATE NEW {insert record type} RECORD via POST. The response code is: \"";
part2 = "\". \n\n - For \'Non-HTTP response code - org.apache.jorphan.util.JMeterStopThreadException\' is received,verify the payload file still exists. \n - For response code = 409, \n\t a) check the payload for validity.\n\t b) verify the same {insert record type} name doesn't already exist in the {insert table name} table. If found, delete record and re-run the test. \n - For response code = 500, verify the database and its host server are reachable. \n";

// Open File(s)
FileOutputStream f = new FileOutputStream(FileServer.getFileServer().getBaseDir() + "\\error.log", true);

//FileOutputStream f = new FileOutputStream("c:\\error.log", true); 
PrintStream p = new PrintStream(f); 

// Write data to file 
p.println( part1 + ResponseCode + part2 );

// Close File(s)
p.close();
f.close();
}

有没有办法让这个可以重新调用,而不是在每个线程组中重复它?现在我有多达 20 个线程组,因此同一断言的 20 个版本.

我查看了此站点上的多个页面以及How to Use BeanShell: JMeter's Favorite Built-in Component,但我没有找到解决此问题的方法。感谢您提供任何反馈。

【问题讨论】:

    标签: api jmeter


    【解决方案1】:

    如果您将断言(任何断言)置于与线程组相同的级别,例如:

    它将同时应用于“Sampler 1”和“Sampler 2”。此外,断言将在每次迭代时应用于每个线程组中的每个采样器。

    请参阅How to Use JMeter Assertions in Three Easy Steps 指南,该指南阐明了断言范围、成本和最佳实践。

    【讨论】:

    • 谢谢。我试试看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多