Skip to main content

How to debug integration tests in a Maven project in IntelliJ IDEA?


What is debugging?

          Debugging code is done in order to locate and fix bugs in it. This is an important step towards producing bug free code which in turn creates reliable software.


So now I will explain how to debug tests in IntelliJ IDEA IDE for a maven project in simple steps.

Debugging integration tests.

Step 1 :

           The maven surefire plugin will be used for this purpose. And the operating system referenced here is Ubuntu with regard to the commands.

First setup break points in the lines of code that you need to debug. For this, you need to simply click on the left corner of the lines in the code editing area where you need the tests to pause during debugging. A red dot will appear when you click.

Step 2 :

Type the following command on the command line after moving into the directory containing your maven project's integration tests.

That is,

  cd <path-to-the-directory-containing-your-maven-project's-integrationtests>

 mvn clean install -Dmaven.surefire.debug

The tests will pause automatically and await a remote debugger on port 5005. (The port 5005 is set as default) You will see a statement in the command line notifying that it is listening in port 5005.

 Listening for transport dt_socket at address: 5005

If you need to configure a different port, you can pass a more detailed value to the above command.

That is,

mvn clean install -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE"

(Note : This is a single command)

This command will use port 8000 instead of 5005.

Step 3 :

If you are running the debugger for the first time, you will have to edit the debugging configurations in the IntelliJ IDEA IDE. If you have already done the configuration and set the remote debugger port to attach to as 5005, there is no need to edit the configurations again.

The debug configurations can be edited as follows.

Go to Run --> Edit Configurations... in the IDE.

In the dialog box that appears, click on the '+' sign that you can see in the top left corner.

Select the 'Remote' option that you can find in the drop down list.

In the next window that appears, specify the port in the place where you have to specify it. Give a name for the configuration as well.

Then say Apply and then click Ok.

Now the configurations are set.

Step 4 :

You can then attach to the running tests using the IDE.

Go to Run --> Debug...

Then select the configuration that you specified before.

Now the tests are attached to the remote debugger.

This is all what you need to do.

The tests will be paused at the break points that you have specified before. The details of the requests coming in and out when the tests are run can be seen in the IDE. You can click and remove the break points one by one and resume the program after each pause, through the IDE.

Happy Debugging. :)





Comments

  1. Thank you for sharing this! What you have shared is very helpful and informative. Would love to see more updates from you.

    Website Development

    ReplyDelete
  2. Really an informative blog...Thanks for sharing an informative article with us.

    python programming tutorials
    best way to learn python

    ReplyDelete
  3. Really an informative blog...Thanks for sharing an informative article with us.
    ethical hacking tutorials
    hacking tutorials tips and tricks

    ReplyDelete
  4. Really nice blog. thanks for sharing such a useful information.
    Testcomplete Online Training

    ReplyDelete
  5. This post is so interactive and informative.keep update more information...
    java training in velachery
    Java training in chennai

    ReplyDelete
  6. I appreciate your blog post on debugging integration tests in a Maven project using IntelliJ IDEA. API Testing Demystified: Tools, Techniques, and Training Resources

    ReplyDelete

Post a Comment

Popular posts from this blog

How to connect my database instance with elastic beanstalk instance in AWS?

If you have deployed your web application in Elastic Beanstalk in AWS and now you need to connect a database to this instance, and your database is actually residing in a different instance, how can you actually connect them? It's easy with Elastic Beanstalk. I will explain an example scenario that I used for connecting my elastic beanstalk web application with another instance containing my MongoDB database. By looking at this, you can customize as per your need. Don't worry. This is easy. :) The only things you need here are the details about the 1. Database name that you need to connect to. Ex:- "myDB" 2. Port at which the database instance is listening. EX:- In the case of MongoDB, the listening port is 27017 3. Host name of your database instance. EX:- Like localhost, in this case, it will be the Public DNS of your database instance 4. The password of your database if exists. First these details need to be set as environment variables in Elastic Be

How to import the Public Certificate of one WSO2 product to the trust store of another?

To demonstrate this point, I will use the 2 products WSO2 API Manager 2.1.0 (referred as APIM from here onwards) and WSO2 Enterprise Integrator 6.1.1 (referred as EI from here onwards). When using EI as the Business Process Server during configuration of Workflows in APIM, one step to perform is to import the public certificate of EI to the truststore of APIM [1]. So now let's see how this can be done. Step 1: Go to <EI_HOME>/repository/resources/security/ folder and execute the following keytool command. This command is used to export the public certificate of EI as a certificate file called wso2carbon.cer. Since the default keystore in EI is wso2carbon.jks, we have specified it as the keystore and the default alias is wso2carbon. Provide wso2carbon as the keystore password when prompted as it is the default password. After executing the above command from within the security folder in EI, you will see that a file with the name of wso2carbon.cer is created