How to debug maven surefire tests in Eclipse

I am trying to debug my Maven Surefire test suite in eclipse. I am using TestNg for the test runner. I can run this command from terminal then kick off a "Remote Java Application" in Eclipse to debug:

mvn clean test -Dmaven.surefire.debug -Dclass=com.myTests.SampleTestClass

Is it possible to set up a Debug Configuration in Eclipse to so I can just Debug directly from Eclipse without having to run the command in terminal?

This is my maven surefire setup in Pom.xml

<plugins>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.17</version>
  <configuration>
    <systemPropertyVariables>
      <my_property>${my_property}</my_property>
    </systemPropertyVariables>
    <properties>
      <property>
        <name>listener</name>
        <value>com.myPackage.TestListener</value>
      </property>       
    </properties>
  </configuration>
 </plugin>
</plugins>

Upvotes: 2

Views: 1963

Answers (1)

Vogel612
Vogel612

Reputation: 5647

As already mentioned by khmarbaise, ditch the maven part and just run the tests from eclipse itself.

The Key-Combination you'll want to use after selecting the package containing your TestNG tests is: Alt + Shift + D, N

To debug JUnitTests, replace the N by T

As to preserving current functionality: To attach a listener to your testng testsuite, use the @Listeners-Annotation, where you can attach multiple classes implementing ITestNGListener to listen to your suite.

Be aware that ITestNGListener is just a marker interface and has no further functionality.

For the systemPropertyVariables defined: You should be able to attach them in your testng run (and debug) configuration.

Upvotes: 2

Related Questions