隐藏maven“;运行com.MyTest“;测井线

隐藏maven“;运行com.MyTest“;测井线,maven,maven-surefire-plugin,Maven,Maven Surefire Plugin,我在mvn输出中获得以下内容: Running com.MyTest Tests run: 1 , Failures: 0 , Errors: 0 , Skipped: 0 , Time elapsed: 0.02 sec - in com.MyTest 尽管有国旗: -Dsurefire.printSummary=false -Dsurefire.useFile=true 有没有办法隐藏第一行-运行com.MyTest 更多信息 <project> <build>

我在mvn输出中获得以下内容:

Running com.MyTest
Tests run: 1 , Failures: 0 , Errors: 0 , Skipped: 0 , Time elapsed: 0.02 sec - in com.MyTest
尽管有国旗:

-Dsurefire.printSummary=false -Dsurefire.useFile=true
有没有办法隐藏第一行-
运行com.MyTest

更多信息

<project>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${maven.surefire.plugin}</version>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.plugin}</version>
        <configuration>
          <includes>
            <include>**/*Test.class</include>
          </includes>
          <parallel>classes</parallel>
          <threadCount>10</threadCount>
          <useFile>false</useFile>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <profiles>
    <profile>
      <id>coverage-per-test</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
              <properties>
                <property>
                  <name>listener</name>
                  <value>org.sonar.java.jacoco.JUnitListener</value>
                </property>
              </properties>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
这应该无关紧要,但我还要补充一点:

-Dlogback.configurationFile=/Users/me/logback.xml
其中logback.xml包含:

<configuration>
  <root level="OFF">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

pom.xml surefire配置

<project>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${maven.surefire.plugin}</version>
        </plugin>
      </plugins>
    </pluginManagement>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.plugin}</version>
        <configuration>
          <includes>
            <include>**/*Test.class</include>
          </includes>
          <parallel>classes</parallel>
          <threadCount>10</threadCount>
          <useFile>false</useFile>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <profiles>
    <profile>
      <id>coverage-per-test</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
              <properties>
                <property>
                  <name>listener</name>
                  <value>org.sonar.java.jacoco.JUnitListener</value>
                </property>
              </properties>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin}
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin}
**/*测试类
班级
10
假的
每次测试的覆盖率
org.apache.maven.plugins
maven surefire插件
2.15
听众
org.sonar.java.jacoco.JUnitListener

对于不显示的这一行,必须不创建控制台记录器。当以下方法返回
true
时:

再往下一行,如果返回
true
,则为和该行的一个实例

因此,要么:

  • 设置(默认值)和,或
  • 您将
    useFile=false
    和(默认值)设置为非
    “简短”
    “普通”
    (默认值为
    “简短”
同样地,通过配置
-Dsurefire.printsummmary=false-Dsurefire.useFile=true
,它应该可以工作,并且该行不应该在控制台中,也不应该在输出文件中。您的问题是
maven-surefire插件的配置设置了
false
POM中配置的任何值都直接优先于您在命令行上设置的值。这是为了确保当POM定义一个值时,它不能被覆盖,并有助于生成可复制的版本

因此,您可以改为强制为
reportFormat
输入一个不正确的值(既不是
“简短”
也不是
“普通”
),并且您会注意到
“运行”
行将不再发出

不过这有点笨重。因此,另一种解决方案是定义Maven属性并在命令行上重写该属性。在你的插件中,有:

<useFile>${surefire.plugin.useFile}</useFile>

这样,构建的行为与以前相同。当您定义
-Dsurefire.plugin.useFile=true
时,您将覆盖Maven属性,这将确保在
useFile
设置为
true

时启动Surefire,我甚至不认为您的logback配置被使用,请查看此答案是的,我知道。我只是将其包括在内,这样我就不会收到通知我配置日志级别的回复。使用此配置
-Dsurefire.printSummary=false-Dsurefire.useFile=true
,您不应该在控制台或输出文件中有该行。刚刚使用Surefire的2.19.1版进行了测试。您正在使用哪个版本的Surefire插件?正确,它是定义
false
的中间版本。这优先于您在命令行上放置的内容。将其设置为
true
,然后重试。不,没有办法。但是您可以设置Maven属性。我会写一个答案。谢谢你花时间解释潜在的因素。因此,我是否应该故意为
reportFormat
使用无效值?我很高兴这样做,我只是希望maven的未来版本不会禁止我这样做。@Sridhar Sarnobat是的,这就是为什么我认为最好不要这样做,并尝试覆盖一个新的maven属性解决方案。它工作起来更简单,而且有文档记录。
<properties>
  <surefire.plugin.useFile>false</surefire.plugin.useFile>
</properties>