Jacoco常用命令

1, Instrument

::Off-line instrumentation of Java class files and JAR files.
::set path=D:\Java\jdk1.6.0_34\bin
set path=D:\Java\jdk1.8.0_131\bin
java -jar jacococli.jar instrument D:\Git_Software\Server\6.2-spring2.5\standalone\deployments\biz-rds.jar --dest classes
pause

2, Dump

::Request execution data from a JaCoCo agent running in 'tcpserver' output mode.
pause
::set path=D:\Java\jdk1.6.0_34\bin
set path=D:\Java\jdk1.8.0_131\bin
java -jar jacococli.jar dump --address localhost --destfile test.exec
pause

3, Merge

::Merges multiple exec files into a new one.
::set path=D:\Java\jdk1.6.0_34\bin
set path=D:\Java\jdk1.8.0_131\bin
java -jar jacococli.jar merge *.exec --destfile merge/all.exec
pause

4, Report

::Generate reports in different formats by reading exec and Java class files.
::set path=D:\Java\jdk1.6.0_34\bin
set path=D:\Java\jdk1.8.0_131\bin
java -jar jacococli.jar report test.exec --classfiles D:\Git_Software\Server\6.2-spring2.5\standalone\deployments\biz-rds.jar --html report.html --sourcefiles E:\workspace4.3ForSNXGit\biz-rds\src\main\java
pause

5, Exec Info

::Print exec file content in human readable format.
::set path=D:\Java\jdk1.6.0_34\bin
set path=D:\Java\jdk1.8.0_131\bin
java -jar jacococli.jar execinfo *.exec
pause

 

 

Jacoco Command Line Interface(cli) Doc Reference (https://www.jacoco.org/jacoco/):

Command Line Interface

JaCoCo comes with a command line interface to perform basic operations from the command line. The command line tools with all dependencies are packaged in jacococli.jar and are available with the JaCoCo download. Java 1.5 or greater is required for execution.

For more sophisticated usage especially with larger projects please use our integrations with various build tools.

The following commands are available. Each command has a list of optional and required parameters. Some parameters can be specified multiple times to provide multiple values.

Warning: Although a instrument command is provided the preferred way for code coverage analysis with JaCoCo is on-the-fly instrumentation with the JaCoCo agent. 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.

dump

java -jar jacococli.jar dump [--address <address>] --destfile <path> [--help] [--port <port>] [--quiet] [--reset] [--retry <count>]

Request execution data from a JaCoCo agent running in 'tcpserver' output mode.

OptionDescriptionRequiredMultiple
--address <address>host name or ip address to connect to (default localhost)  
--destfile <path>file to write execution data to 
--helpshow help  
--port <port>the port to connect to (default 6300)  
--quietsuppress all output on stdout  
--resetreset execution data on test target after dump  
--retry <count>number of retries (default 10)  

instrument

java -jar jacococli.jar instrument [<sourcefiles> ...] --dest <dir> [--help] [--quiet]

Off-line instrumentation of Java class files and JAR files.

OptionDescriptionRequiredMultiple
<sourcefiles>list of folder or files to instrument recusively 
--dest <dir>path to write instrumented Java classes to 
--helpshow help  
--quietsuppress all output on stdout  

merge

java -jar jacococli.jar merge [<execfiles> ...] --destfile <path> [--help] [--quiet]

Merges multiple exec files into a new one.

OptionDescriptionRequiredMultiple
<execfiles>list of JaCoCo *.exec files to read 
--destfile <path>file to write merged execution data to 
--helpshow help  
--quietsuppress all output on stdout  

report

java -jar jacococli.jar report [<execfiles> ...] --classfiles <path> [--csv <file>] [--encoding <charset>] [--help] [--html <dir>] [--name <name>] [--quiet] [--sourcefiles <path>] [--tabwith <n>] [--xml <file>]

Generate reports in different formats by reading exec and Java class files.

OptionDescriptionRequiredMultiple
<execfiles>list of JaCoCo *.exec files to read 
--classfiles <path>location of Java class files
--csv <file>output file for the CSV report  
--encoding <charset>source file encoding (by default platform encoding is used)  
--helpshow help  
--html <dir>output directory for the HTML report  
--name <name>name used for this report  
--quietsuppress all output on stdout  
--sourcefiles <path>location of the source files 
--tabwith <n>tab stop width for the source pages (default 4)  
--xml <file>output file for the XML report  

classinfo

java -jar jacococli.jar classinfo [<classlocations> ...] [--help] [--quiet] [--verbose]

Print information about Java class files at the provided location.

OptionDescriptionRequiredMultiple
<classlocations>location of Java class files 
--helpshow help  
--quietsuppress all output on stdout  
--verboseshow method and line number details  

execinfo

java -jar jacococli.jar execinfo [<execfiles> ...] [--help] [--quiet]

Print exec file content in human readable format.

OptionDescriptionRequiredMultiple
<execfiles>list of JaCoCo *.exec files to read 
--helpshow help  
--quietsuppress all output on stdout  

version

java -jar jacococli.jar version [--help] [--quiet]

Print JaCoCo version information.

OptionDescriptionRequiredMultiple
--helpshow help  
--quietsuppress all output on stdout  

转载于:https://my.oschina.net/jerval/blog/1827637

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JUnit和JaCoCoJava开发中常用的测试框架和代码覆盖率工具。其中JUnit是一个Java语言的单元测试框架,它提供了一些注解和断言方法,可以方便地编写和运行单元测试。而JaCoCo是一个Java代码覆盖率工具,可以帮助我们分析代码的测试覆盖率,从而找出测试不足的地方。 下面是一个使用JUnit和JaCoCo进行单元测试和代码覆盖率分析的例子: ```java import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class UserServiceTest { @Mock private UserMapper userMapper; @InjectMocks private UserService userService; @Test public void testGetUserById() { UserVO user = new UserVO(); user.setId("1"); user.setName("张三"); when(userMapper.selectUserById("1")).thenReturn(user); UserVO result = userService.getUserById("1"); assertEquals("张三", result.getName()); } } ``` 上面的代码演示了如何使用JUnit和Mockito进行单元测试。其中,@RunWith注解表示使用MockitoJUnitRunner来运行测试,@Mock注解表示创建一个模拟的UserMapper对象,@InjectMocks注解表示将模拟的UserMapper对象注入到UserService对象中。在testGetUserById()方法中,我们使用Mockito.when()方法来定义当调用userMapper.selectUserById()方法时返回自定义的UserVO对象。最后,我们使用assertEquals()方法来判断测试结果是否符合预期。 接下来,我们使用JaCoCo来分析上面的代码的测试覆盖率。我们可以在pom.xml文件中添加以下配置: ```xml <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ``` 然后,在命令行中执行以下命令: ``` mvn clean test ``` 执行完毕后,我们可以在target/site/jacoco/index.html文件中查看代码覆盖率报告。报告中会显示每个类和方法的覆盖率情况,以及哪些代码没有被覆盖到。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值