0
我想爲我的螞蟻項目創建JMH類而不創建Maven項目(如官方網站http://openjdk.java.net/projects/code-tools/jmh/上建議的那樣)。如何在Netbeans中爲具有Junit測試類的螞蟻項目創建和運行JMH?
基本上,我有一個螞蟻項目與Restful服務,其中我已經添加了我的Junit測試類,我想測試我的測試類。
這是正常運行(忽略任何邏輯錯誤)我的樣本測試類:
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.embeddable.EJBContainer;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class ManipulateBeanTest {
private static EJBContainer container;
@BeforeClass
public static void setUpClass() {
Map<String, Object> properties = new HashMap<>();
properties.put(EJBContainer.MODULES, new File("build/jar"));
container = EJBContainer.createEJBContainer(properties);
System.out.println("Opening the container");
}
@AfterClass
public static void tearDownClass() {
container.close();
System.out.println("Closing the container");
}
@Test
public void testInsert() throws Exception {
System.out.println("insert");
char code = 'S';
double rate = 99.00;
// Lookup the EJB
System.out.println("Looking up EJB...");
ManipulateBean instance = (ManipulateBean) container.getContext().lookup("java:global/classes/ManipulateBean");
System.out.println("Inserting entities...");
instance.insert(code, rate);
String exp = "S";
String object = instance.verify(code);
System.out.println("JPA call returned: " + object);
System.out.println("Done calling EJB");
Assert.assertTrue("Unexpected number of entities", (exp.equals(object)));
System.out.println("..........SUCCESSFULLY finished embedded test");
}
}
我使用NetBeans,請建議。
如何使用此jmh-ant示例項目來對我的項目進行基準測試,因爲它只是開始基準類MyAntyBench中的方法 – agrawalsp
jmh-ant-sample是_sample_,它描述了使用JMH應該進行的步驟來自Ant。如果您認爲合適,請適應您的項目。您可能需要將annprocess jar連接到編譯您的基準類的javac任務中,如示例中所示。 –
您的意思是我必須在我的build.xml中進行更改才能真正生成benchmarks.jar文件,該文件將對我的測試用例進行基準測試?如果是這樣,那麼這對我來說不是一個可行的解決方案,因爲我有數百個測試類,然後我必須在我的xml文件中進行配置。在這種情況下,你能否建議我以某種方式自動生成基準測試(就像junit插件所在的插件,並開始編寫測試用例一樣)。 – agrawalsp