2014-07-17 84 views
0

我使用cobertura和Maven來生成代碼覆蓋率報告。當沒有足夠的代碼被測試用例覆蓋時,我們希望能夠失敗。基於Maven的-的Cobertura-插件的web page for "check",我配置了我的POM這樣的文件:cobertura:檢查似乎缺少參數

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>cobertura-maven-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <check> 
        <branchRate>85</branchRate> 
        <lineRate>85</lineRate> 
        <haltOnFailure>true</haltOnFailure> 
        <totalBranchRate>85</totalBranchRate> 
        <totalLineRate>85</totalLineRate> 
        <packageLineRate>85</packageLineRate> 
        <packageBranchRate>85</packageBranchRate> 
       </check> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>clean</goal> 
         <goal>check</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>cobertura-maven-plugin</artifactId> 
      <version>2.6</version> 
     </plugin> 
    </plugins> 
</reporting> 

當我執行行家,我得到這個錯誤:

The parameters 'check' for goal org.codehaus.mojo:cobertura-maven-plugin:2.6:check are missing or invalid

我試着在調試模式下,我運行看到這樣的輸出check

 
[INFO] --- cobertura-maven-plugin:2.6:check (default-cli) @ MyApplication --- 
[DEBUG] Configuring mojo org.codehaus.mojo:cobertura-maven-plugin:2.6:check from plugin realm ClassRealm[plugin>org.codehaus.mojo:cobertura-maven-plugin:2.6, parent: [email protected]] 
[DEBUG] Configuring mojo 'org.codehaus.mojo:cobertura-maven-plugin:2.6:check' with basic configurator --> 
[DEBUG] (f) dataFile = G:\dev\MyApplication\target\cobertura\cobertura.ser 
[DEBUG] (f) forceMojoExecution = false 
[DEBUG] (f) maxmem = 64m 
[DEBUG] (f) mojoExecution = org.codehaus.mojo:cobertura-maven-plugin:2.6:check {execution: default-cli} 
[DEBUG] (f) pluginClasspathList = [org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.6:, net.sourceforge.cobertura:cobertura:jar:2.0.3:compile, org.ow2.asm:asm:jar:4.1:compile, org.ow2.asm:asm-tree:jar:4.1:compile, org.ow2.asm:asm-commons:jar:4.1:compile, org.ow2.asm:asm-util:jar:4.1:compile, org.ow2.asm:asm-analysis:jar:4.1:compile, oro:oro:jar:2.0.8:compile, jaxen:jaxen:jar:1.1-beta-8:compile, dom4j:dom4j:jar:1.6.1:compile, jdom:jdom:jar:1.0:compile, xerces:xmlParserAPIs:jar:2.6.2:compile, xerces:xercesImpl:jar:2.6.2:compile, xom:xom:jar:1.0b3:compile, com.ibm.icu:icu4j:jar:2.6.1:compile, xalan:xalan:jar:2.6.0:compile, org.ccil.cowan.tagsoup:tagsoup:jar:0.9.7:compile, org.apache.ant:ant:jar:1.8.3:compile, org.apache.ant:ant-launcher:jar:1.8.3:compile, org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:compile, org.mortbay.jetty:jetty:jar:6.1.14:compile, org.mortbay.jetty:jetty-util:jar:6.1.14:compile, com.sun:tools:jar:0:system, log4j:log4j:jar:1.2.9:compile, net.sourceforge.cobertura:cobertura-runtime:pom:2.0.3:compile, urbanophile:java-getopt:jar:1.0.9:compile, commons-cli:commons-cli:jar:1.0:compile, org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile, org.apache.maven.reporting:maven-reporting-api:jar:2.0.8:compile, org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-9:compile, org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4.2:compile, commons-validator:commons-validator:jar:1.2.0:compile, commons-beanutils:commons-beanutils:jar:1.7.0:compile, commons-digester:commons-digester:jar:1.6:compile, commons-logging:commons-logging:jar:1.0.4:compile, xml-apis:xml-apis:jar:1.0.b2:compile, org.apache.maven.doxia:doxia-core:jar:1.0:compile, org.apache.maven.doxia:doxia-site-renderer:jar:1.0:compile, org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:compile, org.codehaus.plexus:plexus-velocity:jar:1.1.7:compile, org.apache.velocity:velocity:jar:1.5:compile, org.apache.maven.doxia:doxia-decoration-model:jar:1.0:compile, commons-collections:commons-collections:jar:3.2:compile, org.apache.maven.doxia:doxia-module-apt:jar:1.0:compile, org.apache.maven.doxia:doxia-module-fml:jar:1.0:compile, org.apache.maven.doxia:doxia-module-xdoc:jar:1.0:compile, org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:compile, commons-lang:commons-lang:jar:2.4:compile, org.codehaus.plexus:plexus-utils:jar:2.0.2:compile, org.apache.maven.shared:maven-invoker:jar:2.0.11:compile] 
[DEBUG] (f) project = MavenProject: com.mycompany:MyApplication1.0.0 @ G:\dev\MyApplication\pom.xml 
[DEBUG] (f) quiet = false 
[DEBUG] (f) skip = false 
[DEBUG] -- end configuration -- 

我沒有看到任何這顯然是錯誤的,所以我不知道爲什麼我不能運行check

我從RAD 8.5運行Maven的內嵌版本,使用這一目標運行配置:

clean cobertura:check

如果我運行的

clean cobertura:cobertura

檢查過程中沒有按」構建即使我知道我的覆蓋率低於85%,它仍然可以運行並且構建成功。

有沒有人知道cobertura:check有什麼問題,以及如何讓它工作?

回答

0

在插件中你的pom.xml以下使用標記

<plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>cobertura-maven-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <formats> 
         <format>html</format> 
         <format>xml</format> 
        </formats> 
       </configuration> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>cobertura</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

,並在pom.xml中的項目標籤下面使用。

<reporting> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>cobertura-maven-plugin</artifactId> 
       <version>2.6</version> 
      </plugin> 
     </plugins> 
    </reporting> 

這對我的作品