How to debug integration test in IntelliJ? - java

I have created run configuration in Maven Projects for
mvn -Dit.test=PredictionWorkflowTest verify
which looks like 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).

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
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.

Related

Maven and SpringBoot debugging what does -Drun.jvmArguments=-Xdebug really mean

I can start my main Spring Boot application of the shelves in debug mode I can set a breakpoint in IntelliJ and it works! I.e. Running below:
#SpringBootApplication
public class JasperApplication {
public static void main(String[] args) {
SpringApplication.run(JasperApplication.class, args);
}
}
However if I start my Spring Boot application in IntelliJ with the maven run plugin with debug option:
spring-boot:run
Debug does not work. I have read about
-Drun.jvmArguments=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
I can't fit everything together, could someone enlightning me how it all works or direct me to some articles describing the whole thing under the hood.
I like to be able to run maven Spring Boot plugin from within IntelliJ aswell as the command line, being able to debug and set breakpoints. Thanks!
When you invoke spring-boot:run you are starting a remote process i.e. this process is not running inside your IDE.
If you want to debug this process from within your IDE the following pre requisites apply:
The remote process must be 'remote debug aware', this is what you are doing when you run that process with -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
You must use a remote debugger within your IDE. More details in the docs but the brief summary is:
Run > Edit Configurations
Click on the + icon and choose Remote
Name the run configuration and choose a module for the Search sources using module's classpath
The invoke mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" and launch this Run configuration within your IDE and the two will talk to each other.
Here's a screenshot showing the remote run configuration looks like:

TomEE Maven plugin debug w/ IntelliJ

I'm running a Vaadin web app using the TomEE Maven plugin. When attempting to run debug in IntelliJ, it skips all breakpoints.
From what research I've read, it points to the debugger not attaching to the TomEE plugin.
Is there a way to do this without having to configure a standalone server? Ideally for development, I want to keep the dev setup simple and packaged within the pom.
if you run
mvn tomee:debug
then in intellij you configure a remote server on port 5005 and when the lisne "Listen ...5005..." is in the logs you connect/run this debug configuraton.
Then you debug in the server.

IntelliJ debugger not hitting breakpoints in a Maven Java Google App Engine project (Eclipse works)

So I'm starting to pull my hair out here. IntelliJ just doesn't want to trigger breakpoints, whereas Eclipse works just fine. I never thought I'd say that sentence :|
Here's my example:
Create a clean new GAE project from the classic example Google Guestbook archetype
mvn archetype:generate -Dappengine-version=1.9.15
-Dapplication-id=your-app-id -Dfilter=com.google.appengine.archetypes:guestbook-archetype
Uncomment the suggested lines in the pom.xml to allow remote debugging
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.9.15</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
<!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
<!-- address>0.0.0.0</address>
<port>8080</port -->
<!-- Comment in the below snippet to enable local debugging with a remove debugger
like those included with Eclipse or IntelliJ -->
<jvmFlags>
<jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
</jvmFlags>
</configuration>
</plugin>
Run the devserver goal (which compiles, tests and runs the GAE environment)
mvn appengine:devserver
(ECLIPSE: WORKING CASE)
Fire up Eclipse Juno and import the project as a Maven project.
Create a "Remote Java Application" Debug configuration
Set a breakpoint, Debug the app using the Remote config and BAM, breakpoint hit and app stops. As expected.
(INTELLIJ 14: FAIL CASE)
Fire up INTELLIJ and import the project as a Maven project
Create a "Remote Java Application" Debug profile
Set a breakpoint, Debug the app using the Remote config and BAM, breakpoint FAILS to trigger.
Other than the different IDEs, there is no difference in the project setup. This tells me I must be doing something wrong in IntelliJ, but I honestly don't know what.
It just works in Eclipse and doesn't in IntelliJ. :|
Any ideas?
-- Shane
I am not sure if this question is still active.
I think you may have had the same problem I had.Intellij debugger does not stop at breakpoints
Are you sure your server is exposing the 8000 port for debugger to listen when it started. You should provide those JVM parameters if it is not.
I have managed to get it working as follows:
Add JVM flags to Maven/Gradle as suggested by IntelliJ.
Do not use remote (as suggested by GAE documentation). Instead, debug appengineRun Gradle task (similar for Maven).
Once it is up and running, hit Run/Attach to a Local Process.
BAM! The debugger is attached, breakpoint hit and app suspended
it is old question for sure, but this is the answer:
make sure you have in the maven run config -DforkCount=0 -DreuseForks=false
source:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206825095-Breakpoints-don-t-work-when-debugging-maven-project-

How to setup CI for my application with Jenkins

I have a scheduled build in Jenkins which runs everyday at 12:00 AM. I want to set up a CI server for my project. I want to set it such a way that before every build, my application is undeployed and once the build is successful, it's deployed and up again, running on the server. This is possible if I manually add some server in my system and put the shell command in pre-build and post-build actions to undeploy and deploy manually but is it possible directly with Jenkins? As the name suggests, Jenkins - CI server, is there any way how can I do it with Jenkins?
Note: I have maven jetty plugin and have set a goal clean install jetty:run in my application but it doesn't suit my requirement in Jenkins for CI server.
Yes, Jenkins will run any script at any time, so you can do this very easily. You don't need to use pre- and post-build actions. Build steps work very well for this use. You can add multiple steps to a single Jenkins job/project.

How can I run the IntelliJ debugger on unit tests in a Maven project?

I'm working with a multi-artifact Maven project where artifacts in the project have a few dependencies on each other. I am using IntelliJ 9. I'd like to be able to set breakpoints in my unit tests, but when I right-click on the unit tests folder for my artifact and choose "Debug 'All Tests'", I get a Class not found exception referring to a class in a separate Maven artifact.
I can run the Maven "test" goal on the parent artifact and it works fine.
Any ideas? Thanks.
In you run Maven from command line, you will be able to run it with debugger enabled and just attach Idea as remote debugger. That's how I usually use it.
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" test
See http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html
This will allow debugger connection to port 8000 and wait for you to attach before execution.
I wanted to run the unit tests for a specific package.
I was able to get this to work by making a new JUnit run/debug configuration in IntelliJ. I told it to run the tests in the specific package and for "Use classpath and JDK of module", I picked the root Maven artifact.

Categories

Resources