2012-03-05 71 views
4

我們在生成覆蓋率報告的項目中配置了emma。整個設置工作正常,直到我引入PowerMock來模擬一些靜態方法。Emma覆蓋Powermock

當我用@RunWith(PowerMockRunner.class)註釋一個類時,emma試圖再次啓動覆蓋過程並引發addressbind異常。我認爲maven surefire會爲不同的亞軍分配一個新的JVM,而艾瑪嘗試在新的JVM上重新啓動。

我嘗試了surefire forkMode的不同選項,但沒有幫助。 Running util.HttpClientFactoryTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.154 sec Running xxx.util.ServiceConnectorUtilTest EMMA: collecting runtime coverage data ... java.net.BindException: Address already in use: JVM_Bind at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)

想法如何解決這個問題?任何幫助大大appartiated。由於

+0

使用[jacoco](http://www.eclemma.org/jacoco/)。請參閱[在測試階段運行jacoco](http://stackoverflow.com/questions/9531608/which-emma-maven-plugin-should-i-be-using/9533745#9533745) – 2012-03-06 07:37:21

+0

我有同樣的問題,有沒有人找到了解決辦法? – 2012-06-26 14:12:31

+0

https://groups.google.com/forum/?fromgroups#!topic/powermock/FKRGTkYGb9s接縫是相同的問題 – 2012-06-26 14:32:18

回答

2

如果不指定艾瑪插件中使用Maven的版本將默認爲

<groupId>org.sonatype.maven.plugin</groupId> 
<artifactId>emma-maven-plugin</artifactId> 
<version>1.0</version> 

如果您在構建標籤指定1.2(或1.1)的最新版本

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.sonatype.maven.plugin</groupId> 
       <artifactId>emma-maven-plugin</artifactId> 
       <version>1.0</version> 
      </plugin> 
     </plugins> 
    </pluginManagement>... 

問題應該消失

+0

這真的有幫助 – stewenson 2013-11-25 13:38:55

0

碰碰艾瑪插件版本可能適用於普通的Java項目,但com.amazon.emma-機器人的最新Android版本還沒有此修復程序。

只有至少使用兩個不同的JunitClassRunners(例如默認的一個和@RunWith(PowerMockRunner.class))時纔會出現此問題。我開始使用RobolectricTestRunner時面臨同樣的問題。解決方法是爲模塊中的每個測試用例使用相同的JunitClassRunner。例如。使用@RunWith(PowerMockRunner.class),即使是沒有任何PowerMock的簡單JUnit也是如此。