Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA debugger skips breakpoints when debugging Maven tests

I am trying to debug Maven tests in IntelliJ IDEA. When I open IDEA's Maven Projects view and right-click on test goal, I get an option to debug it. Clicking it executes this goal but the execution never stops at any breakpoints. What am I missing?

Thanks.

like image 952
kaqqao Avatar asked Jul 04 '11 15:07

kaqqao


People also ask

How do I debug maven tests in IntelliJ?

In the IDE, add debug points where you want the debugger to pause during execution. Then in the terminal, enter your Maven execution command, replacing mvn with mvnDebug . In IntelliJ, make sure your debugging configuration is selected, then press the “Debug” button.

How do I keep breakpoints in IntelliJ?

Manage breakpoints To do this, go to Settings/Preferences | Build, Execution, Deployment | Debugger and select Drag to the editor or click with middle mouse button. Clicking a breakpoint will then enable or disable it.

Why debug is not working in IntelliJ?

To solve this, simply remove the jar of the debugged module from all modules' dependencies in the Project Structure. If you do not know which modules have the debugged module jar as dependencies, you can use some tools (Eg. Sublime Text, bash, ...) to search for the module name which is stored in Intellij *.

How do I debug test cases in IntelliJ?

Debug failed tests If you don't know why a test fails, you can debug it. In the editor, click the gutter on the line where you want to set a breakpoint. There are different types of breakpoints that you can use depending on where you want to suspend the program. For more information, refer to Breakpoints.


2 Answers

Just disable the forked mode - something like this in your pom file (under project/build/plugins section):

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.14</version> <configuration>     <forkMode>never</forkMode> </configuration> </plugin> 
like image 156
defectus Avatar answered Oct 16 '22 23:10

defectus


One solution would be to use remote debugging:

  1. configure the surefire plugin: <debugForkedProcess>true</debugForkedProcess>;

  2. run the test (will wait for a remote debugger to connect)

  3. create and run a remote debug configuration in IntelliJ (will hit your breakpoint); the port to connect to is 5005.
like image 29
milan Avatar answered Oct 17 '22 00:10

milan