Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging unit tests run on cmd line using Eclipse

I have a fairly large project which has many dependencies, as a result, I won't be able to build it on Eclipse. I am using Maven and I can build the project on command line. I know how to run unit tests on command line.

My question is that is it possible to debug the unit tests running on command line using eclipse?

like image 326
codereviewanskquestions Avatar asked Jul 31 '13 07:07

codereviewanskquestions


People also ask

How do I debug unit test cases in Eclipse?

With the test class open in the Eclipse editor, simply right click in the editor view and select Debug As > TestNG Test. Eclipse will stop at any breakpoints you set just like it would with any other local debug process.

How do I run unit tests in debug mode?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.

How do I run debug mode in Eclipse?

Starting the Debugger. To debug your application, select a Java file with a main method. Right-click on it and select Debug As Java Application. If you started an application once via the context menu, you can use the created launch configuration again via the Debug button in the Eclipse toolbar.


1 Answers

The Maven Surefire Plugin allows for the remote debugging of unit tests.

You simply need to call maven using the following command:

mvn -Dmaven.surefire.debug test

The tests will automatically pause and await a remote debugger on port 5005. You can then attach to the running tests using Eclipse. You can setup a "Remote Java Application" launch configuration via the menu command "Run" > "Open Debug Dialog..."

like image 163
DB5 Avatar answered Oct 07 '22 10:10

DB5