2016-03-01 35 views
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,但我没有找到解决方案。任何反馈意见。

回答

2

如果你在同一级别将您的断言(任何断言)像线程组:

Assertion Thread Groups

将应用到“采样器”和“采样器2”。而且,断言将在每次迭代中应用于每个线程组中的每个采样器。

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

+0

谢谢。我会给它一个镜头。 – David