【问题标题】:Pitest can't detect class of testPitest 无法检测到测试类别
【发布时间】:2016-05-30 07:01:11
【问题描述】:

我的 maven 和 Pitest 配置有问题。

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

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


我有这样的主要来源 /src/main/java/com.plugin..... .java

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


pom.xml 配置:

<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>

.. 他只知道我的带有自动完成功能的源类,而不是我的测试类。


[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

【问题讨论】:

  • 当您运行mvn test 时,maven 是否找到您的测试?另外,在您的配置中尝试&lt;verbose&gt;true&lt;/verbose&gt;
  • 您真的有一个名为com.plugin 的文件夹吗?您的文件夹应命名为 'src/main/java/com/plugin/..' ...注意 java 包名称和映射文件夹结构之间的区别...
  • mvn 测试工作正常 :) 我在 pom.xml 中有以前的“evosuite”配置,我已经删除了它们,现在 ptest 正确地找到了我的测试类。

标签: java maven mutation-testing pitest


【解决方案1】:

我需要将 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>

【讨论】:

    【解决方案2】:

    对于遇到同样问题的人:

    我遇到了同样的问题,我通过在 Pitest 之前运行 mvn test 解决了这个问题。

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

    【讨论】:

      【解决方案3】:

      当我们从 Junit4 迁移到 Junit5 时,它无法正常工作。没有直接对 Junit5 的支持。解决方案是使用 Pitest 的插件 for 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'
          // ...
      }
      

      【讨论】:

        【解决方案4】:

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

        assert 1 + 2 == 3;
        

        当我把它改成 JUnit 的时候:

        import static org.junit.Assert.assertEquals;
        
        assertEquals(1 + 2, 3);
        

        PITest 按预期工作。我没有深入挖掘它为什么会这样工作。

        【讨论】:

          【解决方案5】:

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

          对于 Maven:

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

          对于毕业:

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

          【讨论】:

          • maven 配置对我不起作用。它给出了一个错误。
          • 无法解析 mojo org.pitest:pitest-maven:1.7.3:mutationCoverage 的配置:基本元素“testPlugin”不得包含子元素
          • 为我使用了 junit5
          猜你喜欢
          • 1970-01-01
          • 2018-08-16
          • 1970-01-01
          • 1970-01-01
          • 2018-01-09
          • 1970-01-01
          • 2020-03-04
          • 2021-05-15
          • 1970-01-01
          相关资源
          最近更新 更多