1
我正在执行基本CRUD功能的API测试。为了在每个线程组中创建每个记录类型,我使用为每个线程组定制的相同BeanShell Assertion模板。JMeter:可重新调用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,但我没有找到解决方案。任何反馈意见。
谢谢。我会给它一个镜头。 – David