3 回答
TA贡献1844条经验 获得超8个赞
我按照 Mkyong 先生在Maven 的示例 - PITest 突变测试示例修复了 JUnit 5 和“minion 异常退出”问题。
向下滚动到 pom.xml 部分,在 pom 文件的 build 部分中定义了一个鬼鬼祟祟的 ptest-junit5-plugin 依赖项:
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.8</version>
</dependency>
</dependencies>
这是我在 Maven 测试阶段用于 jacoco 代码覆盖和坑突变的工作 pom.xml。如果您只对pit 部分感兴趣,请随意从构建标签中删除整个 jacoco 插件部分。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>code</groupId>
<artifactId>scans</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!--attach execution to maven's test phase-->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<!-- fail build if line coverage is lover then defined threshold -->
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.9</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.4.10</version>
<!--attach execution to maven's test phase-->
<executions>
<execution>
<id>pit-report</id>
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
</executions>
<!--allows to work with JUnit 5-->
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.9</version>
</dependency>
</dependencies>
<!--optional-->
<configuration>
<targetClasses>
<param>code.scans*</param>
</targetClasses>
<targetTests>
<param>code.scans*</param>
</targetTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我的环境详细信息:
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T02:58:13-05:00)
Maven home: C:\DEV\apache-maven-3.5.2\bin\..
Java version: 1.8.0_221, vendor: Oracle Corporation
Java home: C:\Progra~1\Java\jdk1.8.0_221\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
TA贡献1934条经验 获得超2个赞
依赖项中似乎缺少 JUnit,因此请尝试将以下内容添加到pom.xml:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
TA贡献1836条经验 获得超5个赞
我的设置是这样的:
<profile>
<id>pitest</id>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<configuration>
<targetClasses>
<param>pl.marcinchwedczuk.rfid*</param>
</targetClasses>
<targetTests>
<param>pl.marcinchwedczuk.rfid*Test</param>
</targetTests>
<avoidCallsTo>
<avoidCallsTo>org.slf4j</avoidCallsTo>
</avoidCallsTo>
</configuration>
<executions>
<execution>
<id>run-pitest</id>
<phase>test</phase>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>${maven-pitest-junit.plugin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
添加回答
举报