Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug integration test in IntelliJ?

I have created run configuration in Maven Projects for

mvn -Dit.test=PredictionWorkflowTest verify

which looks like here

enter image description here

and then set breakpoint inside PredictionWorkflowTest. Unfortunately, when I right click this configuration and select to debug it, tests passes as if no breakpoint were set.

How to make breakpoints working?

If I run test by clicking class itself, then breakpoints trigger, but integration conditions don't me (servers not starting).

like image 719
Dims Avatar asked Mar 20 '18 17:03

Dims


People also ask

How do I debug in IntelliJ?

Run the program in debug mode Click the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.

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.


1 Answers

Step 1: Add debug to maven run configuration

You are probably using Maven Failsafe Plugin to run the tests as explained in their documentation

If that's the case you need to add -Dmaven.failsafe.debug (documentation here) to your maven configuration so it becomes

mvn -Dit.test=PredictionWorkflowTest verify -Dmaven.failsafe.debug

When you run this maven command, the debugger will be listening at port 5005 by default

Step 2: Configure remote debugger in IntelliJ

Now in IntelliJ you need to configure a remote debugger configuration on localhost and port 5005

Remote debugger configuration for integration tests

Step 3: Debug your app

Finally, run the maven command. Just before testing it will stop and wait for the debugger to start running the tests. The following message will be displayed in the terminal

Listening for transport dt_socket at address: 5005

Then start remote debugger configured in step 2. This should allow you to debug your app on integration tests break-points.

like image 86
Maher Malaeb Avatar answered Oct 19 '22 12:10

Maher Malaeb