13

My company has recently switched to maven, and the transition was very smooth, but there is one this that annoys me. So earlier, in pre-maven era you could see which test is current class is being run (f.e if you had 40 unit tests in a class, and 2nd test failed you would see it). Now it looks this way: it displays the name of tested class and thats it. You have to wait till all the tests are done in the class to actually see the results (you can stop the test and it will show the progress to the point you stopped, but you don't see anything before actually stopping them). This is really annoying and time consuming in some integration tests.

If anyone knows a solution for this I'd be grateful. Thanks in advance.

Raidmaster
  • 603
  • 2
  • 7
  • 15

2 Answers2

8

You can configure a listener that will print the currently run test on the console. See the sections Using custom listeners and reporters of the junit maven-surefire-plugin documentation or the testng maven-surefire-plugin documentation

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
      <properties>
        <property>
          <name>listener</name>
          <value>com.mycompany.MyResultListener,com.mycompany.MyResultListener2</value>
        </property>
      </properties>
    </configuration>
  </plugin>
SpaceTrucker
  • 13,377
  • 6
  • 60
  • 99
  • 1
    @simleo. I would like to see the link changed to reflect that it is pointing specifically at the JUnit page. There is another page with the same information for adding a listener to a [Maven Surefire TestNG setup](http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html ) – John Chesshir May 19 '17 at 00:29
  • @JohnChesshir I added the link. – SpaceTrucker May 19 '17 at 08:22
  • Instead, why not log the test details from the test itself ? – MasterJoe Jul 01 '20 at 20:41
1

If you use JUnit, you could use a @Rule for this.

If you only want it to apply to when Maven runs the tests, use a System property to en-/disable the output.

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Here is a thread on using Junit @Rule's to print out the current test name: http://stackoverflow.com/q/473401/32453 though you'd have to add it to some test common base class if you wanted more than one unit test to output it [?] – rogerdpack Jun 15 '16 at 18:03
  • Instead, why not log the test details from the test itself ? – MasterJoe Jul 01 '20 at 20:41