Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven Jacoco代码覆盖率-war文件在货物中运行_Maven_Integration Testing_Jacoco_Cargo - Fatal编程技术网

Maven Jacoco代码覆盖率-war文件在货物中运行

Maven Jacoco代码覆盖率-war文件在货物中运行,maven,integration-testing,jacoco,cargo,Maven,Integration Testing,Jacoco,Cargo,我以前问过这个问题,但一直没有得到答案,我想从我读到的博客文章来看,这是可能的,但我无法让它发挥作用 我想在我的maven构建中使用selenium运行集成测试,我正在使用cargo插件将我的war文件部署到tomcat,集成测试是使用selenium进行的。我在启动时将jacoco arg line参数传递给cargo,但无法获得覆盖率结果 我的所有测试都会运行,但每当我查看生成的jacoco集成测试报告时,总是没有覆盖率 我张贴我的整个pom文件,因为它是相当小的,这可能意味着我得到一些帮助

我以前问过这个问题,但一直没有得到答案,我想从我读到的博客文章来看,这是可能的,但我无法让它发挥作用

我想在我的maven构建中使用selenium运行集成测试,我正在使用cargo插件将我的war文件部署到tomcat,集成测试是使用selenium进行的。我在启动时将jacoco arg line参数传递给cargo,但无法获得覆盖率结果

我的所有测试都会运行,但每当我查看生成的jacoco集成测试报告时,总是没有覆盖率

我张贴我的整个pom文件,因为它是相当小的,这可能意味着我得到一些帮助,使这项工作

 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0        http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co</groupId>
<artifactId>netart</artifactId>
<name>MockitoTests</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.2.7.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.10</org.aspectj-version>
    <org.slf4j-version>1.6.6</org.slf4j-version>                      
</properties>

<dependencies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework-version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>[2.3.0,2.3.99]</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>[2.3.0,2.3.99]</version>
    </dependency>

    <!-- AspectJ -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency>

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
        <scope>runtime</scope>
    </dependency>

    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
        <!-- Exclude the Hamcrest core package that comes with JUNIT -->
        <exclusions>
            <exclusion>
                <artifactId>hamcrest-core</artifactId>
                <groupId>org.hamcrest</groupId>
            </exclusion>
        </exclusions>
    </dependency>       
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path-assert</artifactId>
        <version>0.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.github.detro</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.6.201602180812</version>
    </dependency>
</dependencies>

<build>
    <finalName>${project.name}</finalName>

    <plugins>
        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>
                                    com.github.klieber
                                </groupId>
                                <artifactId>
                                    phantomjs-maven-plugin
                                </artifactId>
                                <versionRange>[0.4,)</versionRange>
                                <goals>
                                    <goal>install</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <execute></execute>
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <additionalProjectnatures>
                    <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                </additionalProjectnatures>
                <additionalBuildcommands>
                    <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                </additionalBuildcommands>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArgument>-Xlint:all</compilerArgument>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>org.test.int1.Main</mainClass>
            </configuration>
        </plugin>

        <!-- Jacoco code coverage plugin for maven (see surefire plugin config) -->
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.5.201505241946</version>
            <executions>
                <!-- Prepares the property pointing to the JaCoCo runtime agent which 
                    is passed as VM argument when Maven the Surefire plugin is executed. -->
                <execution>
                    <id>pre-unit-test</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                        <!-- Sets the name of the property containing the settings for JaCoCo 
                            runtime agent. -->
                        <propertyName>surefireArgLine</propertyName>
                        <includes>
                            <include>uk/co/**</include>
                        </includes>
                    </configuration>
                </execution>
                <!-- Ensures that the code coverage report for unit tests is created 
                    after unit tests have been run. -->
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-unit-tests</outputDirectory>
                    </configuration>
                </execution>
                <!-- Prepares the property pointing to the JaCoCo runtime agent which 
                    is passed as VM argument when Maven Failsafe plugin is executed. -->
                <execution>
                    <id>pre-integration-test</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
                        <includes>
                            <include>uk/co/**</include>
                        </includes>
                        <!-- Sets the name of the property containing the settings for JaCoCo 
                            runtime agent. -->
                        <propertyName>failsafeArgLine</propertyName>                                                
                    </configuration>
                </execution>
                <!-- Ensures that the code coverage report for integration tests after 
                    integration tests have been run. -->
                <execution>
                    <id>post-integration-test</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-int-tests</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- Sure fire unit test plugin configuration -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
                <!-- Sets the VM argument line used when unit tests are run. -->
                <argLine>${surefireArgLine}</argLine>
                <!-- Skips unit tests if the value of skip.unit.tests property is true -->
                <skipTests>${skip.unit.tests}</skipTests>
                <!-- Excludes integration tests when unit tests are run. -->
                <excludes>
                    <exclude>**/IT*.java</exclude>
                </excludes>
            </configuration>
        </plugin>

        <!-- Maven Failsafe Plugin for integration testing -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                    <id>default</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- Sets the VM argument line used when integration tests are run. -->
                <argLine>${failsafeArgLine}</argLine>
                <!-- Skips integration tests if the value of skip.integration.tests 
                    property is true -->
                <!-- <skipTests>${skip.integration.tests}</skipTests> -->
                <systemPropertyVariables>
                    <phantomjs.binary>${phantomjs.binary}</phantomjs.binary>
                </systemPropertyVariables>
                    <includes>
                        <include>**/*IT*</include>
                    </includes>                 
            </configuration>                
        </plugin>

        <!-- Installs PhantomJS so it doesn't have to be pre-installed -->
        <plugin>
            <groupId>com.github.klieber</groupId>
            <artifactId>phantomjs-maven-plugin</artifactId>
            <version>0.7</version>
            <executions>
                <execution>
                    <goals>
                        <goal>install</goal>
                    </goals>
                </execution>
            </executions>
            <!-- The version of phantom js -->
            <configuration>
                <version>2.0.0</version>
            </configuration>
        </plugin>

        <!-- Maven Cargo Plugin - starts tomcat or jetty for integration tests -->
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.2.0</version>
            <configuration>
                <type>standalone</type>
                <!-- <skip>${skip.integration.tests}</skip> -->
                <!-- Install apache tomcat into the target directory -->
                <container>
                    <containerId>tomcat7x</containerId>
                    <zipUrlInstaller>
                        <url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.16/bin/apache-tomcat-7.0.16.zip
                        </url>
                        <downloadDir>${project.build.directory}/downloads</downloadDir>
                        <extractDir>${project.build.directory}/extracts</extractDir>
                    </zipUrlInstaller>                      
                </container>
                <deployables>
                    <deployable>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <type>war</type>                           
                    </deployable>
                </deployables>                                  
            </configuration>

            <executions>
                <execution>
                    <id>start container</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <configuration>
                        <configuration>
                            <properties>
                                <cargo.jvmargs>${failsafeArgLine}</cargo.jvmargs>                           
                                <cargo.servlet.port>10001</cargo.servlet.port>                                          
                            </properties>
                        </configuration>
                    </configuration>                                                               
                </execution>
                <execution>
                    <id>stop</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
                <groupId>com.soebes.maven.plugins</groupId>
              <artifactId>maven-echo-plugin</artifactId>
              <version>0.1</version>
              <executions>
                <execution>
                  <phase>pre-integration-test</phase>
                  <goals>
                    <goal>echo</goal>
                  </goals>
                </execution>
              </executions>
            <configuration>
            <echos>
              <echo>This is the Text which will be printed out.</echo>
              <echo>Displaying value of failsafeArgLineProperty</echo>
            <echo>[failsafeArgLine] ${failsafeArgLine}</echo>
            </echos>
          </configuration>
        </plugin>       
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        com.soebes.maven.plugins
                                    </groupId>
                                    <artifactId>
                                        maven-echo-plugin
                                    </artifactId>
                                    <versionRange>
                                        [0.1,)
                                    </versionRange>
                                    <goals>
                                        <goal>echo</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

4.0.0
英国公司
内特
模拟试验
战争
1.0.0-BUILD-SNAPSHOT
1.6
3.2.7.发布
1.6.10
1.6.6                      
org.springframework
spring上下文
${org.springframework版本}
公用记录
公用记录
org.springframework
SpringWebMVC
${org.springframework版本}
org.springframework
弹簧网
${org.springframework版本}
org.mockito
莫基托磁芯
1.9.5
测试
org.springframework
弹簧试验
${org.springframework版本}
测试
com.fasterxml.jackson.core
杰克逊核心
[2.3.0,2.3.99]
com.fasterxml.jackson.core
杰克逊数据绑定
[2.3.0,2.3.99]
org.aspectj
aspectjrt
${org.aspectj版本}
org.slf4j
slf4j api
${org.slf4j版本}
org.slf4j
jcl-over-slf4j
${org.slf4j版本}
运行时
org.slf4j
slf4j-log4j12
${org.slf4j版本}
运行时
log4j
log4j
1.2.15
javax.mail
邮件
javax.jms
jms
com.sun.jdmk
jmxtools
com.sun.jmx
jmxri
运行时
javax.inject
javax.inject
1.
javax.servlet
servlet api
2.5
假如
javax.servlet.jsp
jsp api
2.1
假如
javax.servlet
jstl
1.2
朱尼特
朱尼特
4.7
测试
汉克雷斯特岩芯
org.hamcrest
com.jayway.jsonpath
json路径断言
0.8.1
测试
com.github.detro
幻影驱动程序
1.2.0
测试
org.jacoco
jacocomaven插件
0.7.6.201602180812
${project.name}
org.eclipse.m2e
生命周期映射
1.0.0
com.github.klieber
PhantomJSMaven插件
[0.4,)
安装
maven eclipse插件
2.9
org.springframework.ide.eclipse.core.springnature
org.springframework.ide.eclipse.core.springbuilder
真的
真的
org.apache.maven.plugins
maven编译器插件
2.5.1
1.6
1.6
-Xlint:全部
真的
真的
org.codehaus.mojo
execmaven插件
1.2.1
org.test.int1.Main
org.jacoco
jacocomaven插件
0.7.5.201505241946
单元前测试
配制剂
${project.build.directory}/coverage reports/jacoco-ut.exec
surefireArgLine
英国/公司/**
单元后测试
测试
报告
${project.build.directory}/coverage reports/jacoco-ut.exec
${project.reporting.outputDirectory}/jacoco单元测试
预集成测试
预集成测试
配制剂
${project.build.director
[WARN] [09:31:44.247] Coverage information was not collected. Perhaps you forget to include debug information into compiled classes? 
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <debug>true</debug>
            </configuration>
        </plugin>
    </plugins>
</build>