Junit5 + Jacoco Maven配置

8 篇文章 0 订阅
5 篇文章 0 订阅

Junit依赖参照

官网
中文
依赖关系

maven配置- Jacoco offline-编译时插桩

<?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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.example</groupId>
	<artifactId>junit5-maven-consumer</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>jar</packaging>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
		<junit.version>4.12</junit.version>
		<junit.jupiter.version>5.0.2</junit.jupiter.version>
		<junit.vintage.version>${junit.version}.2</junit.vintage.version>
		<junit.platform.version>1.0.2</junit.platform.version>
	</properties>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.19.1</version>
				<configuration>
					<systemPropertyVariables>
						<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
					</systemPropertyVariables>
					<includes>
						<include>**/Test*.java</include>
						<include>**/*Test.java</include>
						<include>**/*Tests.java</include>
						<include>**/*TestCase.java</include>
					</includes>
					<properties>
						<!-- <includeTags>fast</includeTags> -->
						<excludeTags>slow</excludeTags>
						<!--
						<configurationParameters>
							junit.jupiter.conditions.deactivate = *
						</configurationParameters>
						-->
					</properties>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.junit.platform</groupId>
						<artifactId>junit-platform-surefire-provider</artifactId>
						<version>${junit.platform.version}</version>
					</dependency>
				</dependencies>
			</plugin>
			<plugin>
				<groupId>org.jacoco</groupId>
				<artifactId>jacoco-maven-plugin</artifactId>
				<version>0.8.6-SNAPSHOT</version>
				<executions>
					<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>
					<execution>
						<id>default-report</id>
						<goals>
							<goal>report</goal>
						</goals>
					</execution>
					<execution>
						<id>default-check</id>
						<goals>
							<goal>check</goal>
						</goals>
						<configuration>
							<rules>
								<rule>
									<element>BUNDLE</element>
									<limits>
										<limit>
											<counter>COMPLEXITY</counter>
											<value>COVEREDRATIO</value>
											<minimum>0.60</minimum>
										</limit>
									</limits>
								</rule>
							</rules>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

	<dependencies>
		<!-- required: edit test and extention -->
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-api</artifactId>
			<version>${junit.jupiter.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- required: run junit 5 tests -->
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-engine</artifactId>
			<version>${junit.jupiter.version}</version>
			<scope>test</scope>
		</dependency>
<!--		&lt;!&ndash; optional: junit configure api, used by IDE or build tools &ndash;&gt;-->
<!--		<dependency>-->
<!--			<groupId>org.junit.platform</groupId>-->
<!--			<artifactId>junit-platform-launcher</artifactId>-->
<!--			<version>${junit.platform.version}</version>-->
<!--			<scope>test</scope>-->
<!--		</dependency>-->
		<!-- optional junit 3/4 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>${junit.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- optional run junit 3/4 -->
		<!-- if there is junit 3/4 tests, this is required when run -->
		<dependency>
			<groupId>org.junit.vintage</groupId>
			<artifactId>junit-vintage-engine</artifactId>
			<version>${junit.vintage.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<!--  must be on the classpath  -->
			<groupId>org.jacoco</groupId>
			<artifactId>org.jacoco.agent</artifactId>
			<classifier>runtime</classifier>
			<version>0.8.6-SNAPSHOT</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

</project>

maven配置- Jacoco one-the-fly - 运行时插桩

<?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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.example</groupId>
	<artifactId>junit5-maven-consumer</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>jar</packaging>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
		<junit.version>4.12</junit.version>
		<junit.jupiter.version>5.0.2</junit.jupiter.version>
		<junit.vintage.version>${junit.version}.2</junit.vintage.version>
		<junit.platform.version>1.0.2</junit.platform.version>
	</properties>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.19.1</version>
				<configuration>
					<includes>
						<include>**/Test*.java</include>
						<include>**/*Test.java</include>
						<include>**/*Tests.java</include>
						<include>**/*TestCase.java</include>
					</includes>
					<properties>
						<!-- <includeTags>fast</includeTags> -->
						<excludeTags>slow</excludeTags>
						<!--
						<configurationParameters>
							junit.jupiter.conditions.deactivate = *
						</configurationParameters>
						-->
					</properties>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.junit.platform</groupId>
						<artifactId>junit-platform-surefire-provider</artifactId>
						<version>${junit.platform.version}</version>
					</dependency>
				</dependencies>
			</plugin>
			<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6-SNAPSHOT</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
		</plugins>
	</build>

	<dependencies>
		<!-- required: edit test and extention -->
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-api</artifactId>
			<version>${junit.jupiter.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- required: run junit 5 tests -->
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-engine</artifactId>
			<version>${junit.jupiter.version}</version>
			<scope>test</scope>
		</dependency>
<!--		&lt;!&ndash; optional: junit configure api, used by IDE or build tools &ndash;&gt;-->
<!--		<dependency>-->
<!--			<groupId>org.junit.platform</groupId>-->
<!--			<artifactId>junit-platform-launcher</artifactId>-->
<!--			<version>${junit.platform.version}</version>-->
<!--			<scope>test</scope>-->
<!--		</dependency>-->
		<!-- optional junit 3/4 -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>${junit.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- optional run junit 3/4 -->
		<!-- if there is junit 3/4 tests, this is required when run -->
		<dependency>
			<groupId>org.junit.vintage</groupId>
			<artifactId>junit-vintage-engine</artifactId>
			<version>${junit.vintage.version}</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</project>

更多配置

Junit5 Example
Jacoco Example

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值