Reality-Loop

How to debug your code with cuke4duke

February 02, 2010 | 2 Minute Read
This post was originally posted on my old blog.

cucumber.jpg Cuke4duke is a ATDD/BDD tool for the JVM. The tool is based on Cucumber and uses JRuby to execute.

Out of the box cuke4duke offers three main ways to execute: Ant, Maven or cuke4duke-commandline.

But all of those three approaches are a bit tricky if you want to debug your application when executing in a BDD scenario.

There is some information on the wiki how to achieve it.

Here some more details:


Maven and Remote Debugging

When using Maven, you can add the following lines to your cuke4duke config in your pom.xml:
<plugin>
  <groupId>cuke4duke</groupId>
  <artifactId>cuke4duke-maven-plugin</artifactId>
  <configuration>
    <jvmArgs>
      <jvmArg>-Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.PicoFactory</jvmArg>
      <jvmArg>-Xdebug</jvmArg>
      <jvmArg>-Xnoagent</jvmArg>
      <jvmArg>-Djava.compiler=NONE</jvmArg>
      <jvmArg>-Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y</jvmArg>
    </jvmArgs>

(a running example is here)

When you now run the integration-test phase (ie. mvn verify), then Maven breaks and waits for a debugger to connect:
[INFO] [cuke4duke:cucumber {execution: run-features}]
[INFO] Listening for transport dt_socket at address: 4000

Now you can connect with Eclipse with a new debug configuration (Run->Debug Configurations...). Choose 'Remote Java Application' and configure the same port as you configured in the pom.xml under address:
Screen shot 2010-01-10 at 4.06.36 PM.png
Now execute this debug configuration, and Maven (which is still waiting) will continue after Eclipse successfully connected, and any breakpoints you set in Eclipse will trigger.


Running from the IDE

Another way is to execute the whole enchilada (JRuby, cuke4nuke, cucumber…) directly out of the IDE. In Eclipse this is accomplished with a new Debug Configuration. Choose Java Application then configure it accordingly: Main class: org.jruby.Main
Screen shot 2010-01-10 at 4.13.57 PM.png
Program Arguments:
${M2_HOME}/repository/.jruby/bin/cuke4duke ./target/test-classes features


VM Arguments:
-Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.PicoFactory
Screen shot 2010-01-10 at 4.15.02 PM.png
Classpath: Make sure all needed jars are on the classpath.
Screen shot 2010-01-10 at 4.15.17 PM.png
Now execute this debug configuration and Eclipse will break directly at any breakpoint you set in your sources.

http://www.google.com/s2/favicons?domain=twitter.com follow me on twitter, I need some friends :-)