1

我已經成功開發了ContiPerf 2上的玩具單元測試。 當我在Arquillian單元測試中嘗試相同時,ContiPerf註釋@PerfTest似乎不起作用,而註釋@Required沒有問題。 我的測試類是什麼樣子Arquillian ContiPerf集成

@RunWith(Arquillian.class) 
public class PerformanceFacadeBeanTest { 

    @Rule 
    public ContiPerfRule i = new ContiPerfRule(); 

    @EJB 
    private PerformanceFacadeRemote performanceRemote; 

    @Deployment 
    public static Archive<EnterpriseArchive> createArchive() { 
     ... 
    } 

    @Test 
    @InSequence(value=1) 
    @PerfTest(invocations = 100, threads = 5) 
    @Required(max = 1200, average = 250) 
    public void testPerformanceOnCacheLocal() { 
    testPerformanceOnCache(performanceLocal); 
    } 

    private void testPerformanceOnCache(PerformanceFacade performanceFacade) { 
    performanceFacade.performOnCache(); 
    } 
} 

和我得到的例外是

org.databene.contiperf.PerfTestExecutionError: org.junit.internal.runners.model.MultipleFailureException: There were 2 errors: 
    java.lang.NullPointerException(null) 
    java.lang.NullPointerException(null) 
    at org.databene.contiperf.util.ContiPerfUtil.executionError(ContiPerfUtil.java:66) 
    at org.databene.contiperf.junit.JUnitInvoker.invoke(JUnitInvoker.java:54) 
    at org.databene.contiperf.util.InvokerProxy.invoke(InvokerProxy.java:46) 
    at org.databene.contiperf.PerformanceTracker.invoke(PerformanceTracker.java:97) 
    at org.databene.contiperf.CountRunner.run(CountRunner.java:52) 
    at java.lang.Thread.run(Thread.java:722) 

有什麼想法? 如果需要,我可以發佈我的pom.xml文件。

回答

0

目前,您不能在Arquillian中使用ContiPerf2。目前,Arquillian使用ThreadLocal實例進行簿記,ContiPerf規則產生的線程無法使用該實例。因此,自Arquillian testrunner之後,NullPointerException將無法​​在除一個線程外的所有線程中找到ThreadLocal實例。 Arquillian的這種行爲可能會在未來版本中發生變化;在那方面沒有承諾。

我現在推薦使用JUnitBenchmarks,因爲據報道通過自定義的Arquillian擴展可以正常工作。