1

I get the following in my mvn output:

Running com.MyTest
Tests run: 1 , Failures: 0 , Errors: 0 , Skipped: 0 , Time elapsed: 0.02 sec - in com.MyTest

despite having the flags:

-Dsurefire.printSummary=false -Dsurefire.useFile=true

Is there a way to hide the first line - Running com.MyTest?

More information

It should be irrelevant, but I also add this:

-Dlogback.configurationFile=/Users/me/logback.xml

with the logback.xml containing:

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

pom.xml surefire configuration

<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>
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
  • I don't think your logback confg is even used, check out this answer http://stackoverflow.com/a/12276898/1743880 – Tunaki Oct 06 '16 at 20:57
  • Yeah I know. I just included that so that I don't get replies telling me to configure the log level. – Sridhar Sarnobat Oct 06 '16 at 21:03
  • 1
    With this configuration `-Dsurefire.printSummary=false -Dsurefire.useFile=true`, you should not have that line, neither in the console nor in the output file. Just tested with version 2.19.1 of Surefire. Which version of Surefire Plugin are you using? – Tunaki Oct 06 '16 at 21:25
  • `maven.surefire.plugin` = `2.19.1`. Hmmm, this is not the first time I've seen different behavior in my environment compared to the documentation. The previous time there was something overriding it in the pom.xml file (e.g. a profile or goal). So the problem's at my end. Thanks. – Sridhar Sarnobat Oct 06 '16 at 21:37
  • Maybe you could post your POM, or the configuration of the Surefire Plugin? – Tunaki Oct 06 '16 at 21:40
  • Updated (with just the relevant parts, I can't post company-specific stuff). Unfortunately there are multiple usages of the plugin so half the battle is figuring out which one is being used (I'm guessing it's just the middle one). – Sridhar Sarnobat Oct 06 '16 at 21:46
  • 1
    Correct, it is the middle one that defines `false`. This takes precedence over what you put on the command line. Set that to `true` and try again. – Tunaki Oct 06 '16 at 22:08
  • Is there a way to override the pom.xml? It seems a bit backwards to me that the file takes precedence over the command. I don't want to temporarily edit the pom.xml then remember to revert it before merging my code :( – Sridhar Sarnobat Oct 06 '16 at 22:09
  • 1
    No, there's no way. But you can set a Maven property. I will write an answer for that. – Tunaki Oct 06 '16 at 22:11
  • I must have the term maven diarrhea in here somewhere to that maven developers take notice. It was removed from the body of my post. – Sridhar Sarnobat Oct 24 '16 at 18:19
  • In all honesty, I removed that, and please do not add it again. It's not constructive and borderline offensive towards the maintainers of the project. If there is something you want improved, feel free to create issues on the JIRA bug tracker, we're looking into them as they come. – Tunaki Oct 24 '16 at 18:24
  • I do not have that much free time on my hands. I'm surprised how no one has ever felt the need to address this. Unix philosophy: Rule of Silence Developers should design programs so that they do not print unnecessary output. This rule aims to allow other programs and developers to pick out the information they need from a program's output without having to parse verbosity. https://en.wikipedia.org/wiki/Unix_philosophy – Sridhar Sarnobat Oct 24 '16 at 18:28
  • Eh, well that is more of a philosophical discussion :). If you want to get rid of the logs and just have the test output, you could also use the `-q` option, redirect the test output to a file, and read the file. For parsing purposes, this will simpler. You can also set a custom `simplelogger.properties` and control exactly the logs written for Maven globally, take a [look here](https://maven.apache.org/maven-logging.html). – Tunaki Oct 24 '16 at 18:34
  • Thanks, I'll take a look. I'm not confident me filing a ticket is going to get this fixed because of the complexity & bureaucracy. And I apologize - I certainly don't mean to offend the developers personally. – Sridhar Sarnobat Oct 24 '16 at 18:50
  • Good criticism is always welcomed :), and thanks for your input. – Tunaki Oct 24 '16 at 18:54

1 Answers1

2

For this particular line not to be shown, it is necessary that no console logger should be created. The code is creating this logger when the following method returns true:

private boolean shouldReportToConsole()
{
    return isUseFile() ? isPrintSummary() : isRedirectTestOutputToFile() || isBriefOrPlainFormat();
}

Further down the line, if this returns true, an instance of ConsoleReporter is created and it will write that line when the tests are started.

So either:

As such, with your configuration of -Dsurefire.printSummary=false -Dsurefire.useFile=true, it should work, and that line should not be in the console, nor should it be in the output file. Your problem is that the configuration of the maven-surefire-plugin sets <useFile>false</useFile>. Any value configured in the POM takes direct predence over what you set on the command-line. This is to make sure that when the POM defines a value, it cannot be overriden and helps to have reproducible builds.

So what you could do instead is force an incorrect value for the reportFormat (which would be neither "brief" nor "plain"), and you'll notice the "Running " line won't be emitted any longer.

That is a bit clunky though. So another solution would be to define a Maven property and override that property on the command-line. In your plugin, have:

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

and define a property, which defaults to false:

<properties>
  <surefire.plugin.useFile>false</surefire.plugin.useFile>
</properties>

This way, the build behave the same as before. And when you define -Dsurefire.plugin.useFile=true, you'll override the Maven property and this will make sure Surefire boots with useFile set to true.

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Thanks for taking the time to explain the underlying factors. So should I deliberately use an invalid value for `reportFormat`? I'm happy to do that, I just hope that a future version of maven doesn't forbid me from doing so. – Sridhar Sarnobat Oct 07 '16 at 00:06
  • @Sridhar-Sarnobat Yes, that is why I think it would be preferable not to do that, and go for the override of a new Maven property solution. It's simpler and documented to work. – Tunaki Oct 07 '16 at 07:32