PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : 发现 0 个测试

问题描述

我正在尝试将 PIT 测试集成到我的项目中。

这是我的 pom.xml 文件

pom.xml

<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>com2.com3.app</groupId>
  <artifactId>team-10</artifactId>
  <version>1.0-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <directory>target</directory>
    <testSourceDirectory>test</testSourceDirectory>
    <testOutputDirectory>target/classes</testOutputDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>11</source>
          <target>11</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19.1</version>
        <dependencies>
          <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.0.0</version>
          </dependency>
          <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.0.0</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.4.6</version>
        <configuration>
          <targetClasses>
            <param>com1.com2.com3.impl.app.LsApplication</param>
          </targetClasses>
          <targetTests>
            <param>com1.com2.com3.impl.app.LsApplicationTest</param>
          </targetTests>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <myTestSourceDirectory>test</myTestSourceDirectory>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.3</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.7.0</version>
    </dependency>
    <dependency>
      <groupId>org.pitest</groupId>
      <artifactId>pitest-junit5-plugin</artifactId>
      <version>0.7</version>
    </dependency>
  </dependencies>
</project>

我的项目正在使用 Maven,但目前未遵循认结构。源代码存储在src/com1.com2.com3,而测试代码存储在test/com1.com2.com3

我运行了 mvn clean install,它运行了我使用 surefire 创建的所有测试文件,但所有这些都导致失败。

然后我继续运行 mvn org.pitest:pitest-maven:mutationCoverage,它产生以下输出,它传入 2 个类文件一个是源文件,1 个是类文件。但是,没有检测到任何测试。测试在 JUnit 下运行良好,我会在这里遗漏什么?如果需要更多信息,请告诉我。

[INFO] Found plugin : Default csv report plugin
[INFO] Found plugin : Default xml report plugin
[INFO] Found plugin : Default html report plugin
[INFO] Found plugin : Static initializer code detector plugin
[INFO] Found plugin : Static initializer filter plugin
[INFO] Found plugin : Excluded annotations plugin
[INFO] Found plugin : Inlined finally block filter plugin
[INFO] Found plugin : Try with resources filter
[INFO] Found plugin : Implicit null check filter
[INFO] Found plugin : For each loop filter
[INFO] Found plugin : Logging calls filter
[INFO] Found plugin : Infinite for loop filter
[INFO] Found plugin : Long running iterator loop filter
[INFO] Found plugin : For loop counter filter
[INFO] Found plugin : Kotlin junk mutations filter
[INFO] Found plugin : Max mutations per class limit
[INFO] Found plugin : Equals shortcut equivalent mutant filter
[INFO] Found plugin : Trivial return vals equivalence filter
[INFO] Found plugin : Mutant export plugin
[INFO] Found shared classpath plugin : Default mutation engine
[INFO] Found shared classpath plugin : JUnit plugin
[INFO] Found shared classpath plugin : TestNG plugin
[INFO] Adding org.pitest:pitest to SUT classpath
[INFO] Mutating from /Users/prashin/target/classes
3:10:40 pm PIT >> INFO : Verbose logging is disabled. If you encounter a problem,please enable it before reporting an issue.
3:10:40 pm PIT >> INFO : Sending 2 test classes to minion
3:10:40 pm PIT >> INFO : Sent tests to minion
3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : Checking environment

3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : Found  0 tests

3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : Dependency analysis reduced number of potential tests by 0

3:10:40 pm PIT >> INFO : MINION : 3:10:40 pm PIT >> INFO : 0 tests received

3:10:40 pm PIT >> INFO : Calculated coverage in 0 seconds.
3:10:40 pm PIT >> INFO : Created  1 mutation test units                                                                                                                    /3:10:41 pm PIT >> INFO : Completed in 1 seconds
================================================================================
- Mutators
================================================================================
> org.pitest.mutationtest.engine.gregor.mutators.ConditionalsBoundaryMutator
>> Generated 8 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 8 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.IncrementsMutator
>> Generated 3 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 3 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.VoidMethodCallMutator
>> Generated 10 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 10 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.ReturnValsMutator
>> Generated 25 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 25 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.MathMutator
>> Generated 5 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 5 
--------------------------------------------------------------------------------
> org.pitest.mutationtest.engine.gregor.mutators.NegateConditionalsMutator
>> Generated 51 Killed 0 (0%)
> KILLED 0 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 
> NO_COVERAGE 51 
--------------------------------------------------------------------------------
================================================================================
- Timings
================================================================================
> scan classpath : < 1 second
> coverage and dependency analysis : < 1 second
> build mutation tests : < 1 second
> run mutation analysis : < 1 second
--------------------------------------------------------------------------------
> Total  : < 1 second
--------------------------------------------------------------------------------
================================================================================
- Statistics
================================================================================
>> Generated 102 mutations Killed 0 (0%)
>> Ran 0 tests (0 tests per mutation)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.249 s
[INFO] Finished at: 2021-03-21T15:10:41+08:00
[INFO] ------------------------------------------------------------------------






 

解决方法

首先为什么要更改默认值,例如源目录等。遵循约定更容易。所以删除以下内容:

<sourceDirectory>src</sourceDirectory>
<directory>target</directory>
<testSourceDirectory>test</testSourceDirectory>
<testOutputDirectory>target/classes</testOutputDirectory>

并根据 maven 约定更改项目的目录布局。

其次,如果您使用 junit jupiter,则必须至少使用surefire 2.22.2 更好的最新版本(3.0.0-M5)。

此外,您使用的 junit jupiter 5.0.0 已经有大约 3 年的历史了……您应该转到最新版本 (5.7.1) 并且您正在手动定义不应完成的 junit-platform-surefire-provider不再(长时间)...

您使用的 pitest-maven 版本非常旧(最近的 1.6.4),最后 pitest-junit5-plugin 应定​​义为 pitest-maven-plugin 的依赖项,同时 0.14 版本已发布。

您可以查看这样的示例项目:https://github.com/khmarbaise/kata-fraction/blob/master/pom.xml

您还混合了不同的概念:

maven-compiler-plugin 的配置:

<configuration>
  <source>11</source>
  <target>11</target>
</configuration>

和基于属性的方法:

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
  <myTestSourceDirectory>test</myTestSourceDirectory>
</properties>

那么最后一个问题是:JDK 8 还是 JDK11?

如果您使用 JDK11,您应该只设置这些选项,而不是同时设置两个选项,然后您可以检查使用 --release 11 via (<maven.compiler.release>11</maven.compiler.release> property based)..

终于看到你有依赖了:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
</dependency>

这是否意味着您正在使用基于 JUnit 4 的单元测试?如果是这样,您必须添加 junit-vintage-engine,以便您可以通过 JUnit Jupiter 运行基于 JUnit 4 的测试。 我强烈建议将所有基于 JUnit 4 的测试迁移到 JUnit Jupiter,然后移除对 junit 4 的依赖。

,

我们有非常详细的文档。它包含示例以及指向我们在 GitHub 上的集成测试的链接。请在您的浏览器 https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html 中打开此链接,如果有不清楚的地方,请随时提出问题。我们很乐意回答这些问题。