Pitest无法检测测试类别

时间:2016-02-18 08:06:41

标签: java maven mutation-testing pitest

我的配置maven和pitest有问题。

Pitest代变异是可以的,但他看不到我的测试类......

如果您有任何解决方案:D

我的主要来源是/src/main/java/com.plugin ..... .java

我有像/src/test/java/com.plugin那样的测试源...... .java

pom.xml config:

<plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <version>1.1.9</version>
            <configuration>
                <targetClasses>
                    <param>com.plugin.business.centre*</param>
                </targetClasses>
                <targetTests>
                    <param> com.plugin.business.centre*</param>
                </targetTests>
            </configuration>
    </plugin>

in&lt; targetTests&gt; ..他只知道我的自动完成源类而不是我的测试类。

[INFO] --- pitest-maven:1.1.9:mutationCoverage (default-cli) @ Polux ---
[INFO] Found plugin : Default csv report plugin
[INFO] Found plugin : Default xml report plugin
[INFO] Found plugin : Default html report plugin
[INFO] Found plugin : Default limit mutations plugin
[INFO] Found shared classpath plugin : Default mutation engine
[INFO] Adding org.pitest:pitest to SUT classpath
[INFO] Mutating from /Users/Mods/Documents/*****/target/classes
08:35:36 PIT >> INFO : Verbose logging is disabled. If you encounter an problem please enable it before reporting an issue.
08:35:36 PIT >> INFO : MINION : objc[677]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be us
08:35:36 PIT >> INFO : MINION : ed. Which one is undefined.

08:35:37 PIT >> INFO : Sending 0 test classes to minion
08:35:37 PIT >> INFO : Sent tests to minion
08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : Checking environment

08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : Found  0 tests

08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : Dependency analysis reduced number of potential tests by 0

08:35:37 PIT >> INFO : MINION : 08:35:37 PIT >> INFO : 0 tests received

08:35:37 PIT >> INFO : Calculated coverage in 0 seconds.
08:35:37 PIT >> INFO : Created  20 mutation test units

5 个答案:

答案 0 :(得分:4)

对于遇到同样问题的人来说:

我遇到了同样的问题,我通过在Pitest之前运行mvn test来修复它。

Pitest不知何故需要执行至少一个测试才能找到它们。

答案 1 :(得分:0)

Pitest无法自动找到testPlugin,请手动设置:

对于Maven:

<testPlugin>
    <value>junit5</value>
</testPlugin>

对于gradle:

pitest {
    testPlugin = "junit5" //or another test plugin
    ...
}

答案 2 :(得分:0)

我需要添加junit5插件作为依赖项(因为我正在使用JUnit 5)。

<plugin>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-maven</artifactId>
    <version>1.4.5</version>
    <dependencies>
        <dependency>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-junit5-plugin</artifactId>
            <version>0.8</version>
        </dependency>
    </dependencies>
    <configuration>
        ...
    </configuration>
</plugin>

答案 3 :(得分:0)

未检测到我的测试,因为我使用了Java内置的assert,例如:

assert 1 + 2 == 3;

当我将其更改为JUnit时:

import static org.junit.Assert.assertEquals;

assertEquals(1 + 2, 3);

PITest可以正常工作。我没有更深入地研究它为何如此工作。

答案 4 :(得分:0)

当我们从Junit4迁移到Junit5时,它不起作用。直接不支持Junit5。解决方案是将pitest的插件用于Junit5 请参阅https://github.com/pitest/pitest-junit5-plugin

plugins {
    id 'java'
    id 'info.solidsoft.pitest' version '1.5.1'
}

pitest {
    //adds dependency to org.pitest:pitest-junit5-plugin and sets "testPlugin" to "junit5"
    junit5PluginVersion = '0.12'
    // ...
}