jacoco 介绍 与offline 模式

Prerequisites

The JaCoCo Maven plug-in requires

  • Maven 2.1.0 or higher and
  • Java 1.5 or higher (for both, the Maven runtime and the test executor).

Usage

The Maven plug-in can be included in your build with the following declaration. Please check here for the latest release version in the repository.

 
 
  1. <plugin>
  2.   <groupId>org.jacoco</groupId>
  3.   <artifactId>jacoco-maven-plugin</artifactId>
  4.   <version>0.7.10-SNAPSHOT</version>
  5. </plugin>
官方地址: http://www.eclemma.org/jacoco/trunk/doc/maven.html


Goals

The JaCoCo Maven plug-in defines the following goals:

重点使用的是report,agent,instrunment(restore-instrumented-classes 配合使用的)。

例如:

 <execution>
        <goals>
            <goal>prepare-agent</goal>
        </goals>
    </execution>
    <execution>
        <id>report</id>
        <phase>prepare-package</phase>
        <goals>
            <goal>report</goal>
        </goals>
    </execution>
<execution>
	<id>default-instrument</id>
	<goals><goal>instrument</goal>
	</goals></execution>
	<execution>
	<id>default-restore-instrumented-classes</id>
	<goals><
	goal>restore-instrumented-classes
	</goal><
	/goals>
	</execution>
离线模式下:
<id>default-instrument</id>
	<goals><goal>instrument</goal>
	</goals></execution>
	<execution>
	<id>default-restore-instrumented-classes</id>
	<goals><
	goal>restore-instrumented-classes
	</goal><
	/goals>
	</execution>
是要添加的!!!!!!!

官方对 offline说明:
Performs offline instrumentation. Note that after execution of test you must restore original classes with help of "restore-instrumented-classes" goal.The preferred way for code coverage analysis with JaCoCo is on-the-fly instrumentation. Offline instrumentation has several drawbacks and should only be 
used if a specific scenario explicitly requires this mode. Please consult documentation about offline instrumentation before using this mode.翻译:
执行离线模式。注意,在执行测试之后,您必须借助“恢复模式化类”的目标恢复原来的类。与jacoco代码覆盖分析的首选方法是在线模式。离线模式有几个缺点,只有在特定场景明确需要这种模式时才应该使用。在使用此模式之前,请参阅有关脱机设备的文档。
离线官方说明:http://www.eclemma.org/jacoco/trunk/doc/offline.html
离线实际上使用了代理,java agent。

<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.7.7.201606060606</version>
<classifier>runtime</classifier>
</dependency>
对于 agent 与 mock 冲突 参考参数:http://www.jacoco.org/jacoco/trunk/doc/agent.html

The JaCoCo agent accepts the following options:

Option Description Default
destfile Path to the output file for execution data. jacoco.exec
append If set to true and the execution data file already exists, coverage data is appended to the existing file. If set to false, an existing execution data file will be replaced. true
includes A list of class names that should be included in execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?). Except for performance optimization or technical corner cases this option is normally not required. * (all classes)
excludes A list of class names that should be excluded from execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?). Except for performance optimization or technical corner cases this option is normally not required. empty (no excluded classes)
exclclassloader A list of class loader names that should be excluded from execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?). This option might be required in case of special frameworks that conflict with JaCoCo code instrumentation, in particular class loaders that do not have access to the Java runtime classes. sun.reflect.DelegatingClassLoader
inclbootstrapclasses Specifies whether also classes from the bootstrap classloader should be instrumented. Use this feature with caution, it needs heavy includes/excludes tuning. false
inclnolocationclasses Specifies whether also classes without a source location should be instrumented. Normally such classes are generated at runtime e.g. by mocking frameworks and are therefore excluded by default. false
sessionid A session identifier that is written with the execution data. Without this parameter a random identifier is created by the agent. auto-generated
dumponexit If set to true coverage data will be written on VM shutdown. The dump can only be written if either file is specified or the output is tcpserver/tcpclient and a connection is open at the time when the VM terminates. true
output Output method to use for writing coverage data. Valid options are:
  • file: At VM termination execution data is written to the file specified in the destfile attribute.
  • tcpserver: The agent listens for incoming connections on the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
  • tcpclient: At startup the agent connects to the TCP port specified by the address and port attribute. Execution data is written to this TCP connection.
  • none: Do not produce any output.
Please see the security considerations below.
file
address IP address or hostname to bind to when the output method is tcpserver or connect to when the output method is tcpclient. In tcpserver mode the value "*" causes the agent to accept connections on any local address. loopback interface
port Port to bind to when the output method is tcpserver or connect to when the output method is tcpclient. In tcpserver mode the port must be available, which means that if multiple JaCoCo agents should run on the same machine, different ports have to be specified. 6300
classdumpdir Location relative to the working directory where all class files seen by the agent are dumped to. This can be useful for debugging purposes or in case of dynamically created classes for example when scripting engines are used. no dumps
jmx If set to true the agent exposes functionality via JMX under the name org.jacoco:type=Runtime. Please see the security considerations below.

参数 exclclassloader:
应该从执行分析中排除的类加载器名称的列表。 列表条目以冒号(:)分隔,可以使用通配符(*和?)。
如果特殊框架与JaCoCo代码工具发生冲突,特别是无法访问Java运行时类的类加载器,则可能需要此选项。


参数:inclbootstrapclasses:
指定是否还应该检测引导类加载器的类。 谨慎使用此功能,需要大量包括/不包括调整。


参数:inclnolocationclasses
指定是否还应该检测没有源位置的类。 通常这样的类是在运行时通过mock框架产生的,因此被排除在默认情况下。


jmock原理简单说明》 了解什么jmock ,以及何时进行的字节码注入。 就知道为什么 需要上面的参数,避免 字节码注入的冲突了。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值