Answers: <p>So I have choosed implementing my own RunListener. I added a compile,test dependency on it to all my other modules and hooked it up in maven surefire plugin configuration. See also <a href="https://stackoverflow.com/questions/61206966/surefire-only-reports-first-test-suite-from-module-to-runlistener">https://stackoverflow.com/questions/61206966/surefire-only-reports-first-test-suite-from-module-to-runlistener</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-04-15T11:19:14.967Z
Answers: 2020-04-15T11:19:14.967Z
Answers: alamar
Body: <p>So we have a TeamCity with numerous JUnit 4 test suites builds configured.</p>
  
  <p>The problem: Tests tab is only populated after build is complete. If build crashes, tests tab is not populated, even with tests which completed before crash.</p>
  
  <p>The reason for that is Surefire reporting the following to teamcity:</p>
  
  <pre><code>##teamcity[importData tc:tags='tc:internal' type='surefire' path='.../target/surefire-reports/TEST-*.xml' whenNoDataPublished='nothing' logAsInternal='true']
  </code></pre>
  
  <p>So TeamCity cannot know the state of tests until suite is done and XML file is written.</p>
  
  <p>Now, TeamCity supports real-time <a href="https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingTests" rel="nofollow noreferrer">tests reporting</a> with messages such as</p>
  
  <pre><code>##teamcity[testStarted name='MyTest.test1']
  ##teamcity[testFailed name='MyTest.test1' message='failure message' details='message and stack trace']
  ##teamcity[testFinished name='MyTest.test1']
  </code></pre>
  
  <p>However, Surefire (the framework responsible for running JUnit tests in Maven) does not output such messages by default.</p>
  
  <p>So it seems that I have three choices if I want tests to be reported in real-time:</p>
  
  <ul>
  <li>Configure a <a href="https://github.com/mbruggmann/junit-teamcity-reporter/blob/master/src/main/java/ch/mbruggmann/junit/JUnitTeamcityReporter.java" rel="nofollow noreferrer">RunListener</a> for JUnit/Surefire to output these messages for TeamCity. Obvious problem here is that I am reinventing the wheel here. I'm also not sure that my reporting of tests will closely match Surefire's reporting of tests in XML file, which may lead to glitches and duplication of tests.</li>
  <li>Change my tests to emit these messages. Easily doable since I have a common superclass for almost all tests, but reinventing the wheel is still there, as well as mismatch with XML.</li>
  <li>Find a way to either configure Surefire to output these messages, or make TeamCity talk to SureFire to enable their output. I recognize that Surefire is hit-or-miss thing, but this functionality is so popular I expect it has <em>some</em> solution.</li>
  </ul>
  
  <p>Please help me choosing between these options. I have tried googling, the results are very poor.</p>
  
Tags: <maven><teamcity>
Title: Make TeamCity see test results in real time using Maven, JUnit 4 and Surefire
UserDisplayName: alamar
ThreadText: # Make TeamCity see test results in real time using Maven, JUnit 4 and Surefire
  
  (Asked by: username_0 on 2020-04-03)
  
  So we have a TeamCity with numerous JUnit 4 test suites builds configured.
  
  The problem: Tests tab is only populated after build is complete. If build crashes, tests tab is not populated, even with tests which completed before crash.
  
  The reason for that is Surefire reporting the following to teamcity:
  
  ```
  ##teamcity[importData tc:tags='tc:internal' type='surefire' path='.../target/surefire-reports/TEST-*.xml' whenNoDataPublished='nothing' logAsInternal='true']
  
  ```
  
  So TeamCity cannot know the state of tests until suite is done and XML file is written.
  
  Now, TeamCity supports real-time [tests reporting](https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html#BuildScriptInteractionwithTeamCity-ReportingTests) with messages such as
  
  ```
  ##teamcity[testStarted name='MyTest.test1']
  ##teamcity[testFailed name='MyTest.test1' message='failure message' details='message and stack trace']
  ##teamcity[testFinished name='MyTest.test1']
  
  ```
  
  However, Surefire (the framework responsible for running JUnit tests in Maven) does not output such messages by default.
  
  So it seems that I have three choices if I want tests to be reported in real-time:
  
  * Configure a [RunListener](https://github.com/mbruggmann/junit-teamcity-reporter/blob/master/src/main/java/ch/mbruggmann/junit/JUnitTeamcityReporter.java) for JUnit/Surefire to output these messages for TeamCity. Obvious problem here is that I am reinventing the wheel here. I'm also not sure that my reporting of tests will closely match Surefire's reporting of tests in XML file, which may lead to glitches and duplication of tests.
  * Change my tests to emit these messages. Easily doable since I have a common superclass for almost all tests, but reinventing the wheel is still there, as well as mismatch with XML.
  * Find a way to either configure Surefire to output these messages, or make TeamCity talk to SureFire to enable their output. I recognize that Surefire is hit-or-miss thing, but this functionality is so popular I expect it has *some* solution.
  
  Please help me choosing between these options. I have tried googling, the results are very poor.
  
  **Tags:** maven, teamcity
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-04-15. Score: 1 | Accepted answer
  
  So I have choosed implementing my own RunListener. I added a compile,test dependency on it to all my other modules and hooked it up in maven surefire plugin configuration. See also <https://stackoverflow.com/questions/61206966/surefire-only-reports-first-test-suite-from-module-to-runlistener>
  
  
  ---
  
  