2016-03-01 78 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