Tuesday, February 2, 2010

How to debug your code with cuke4duke

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.

5 comments:

  1. Thanks Jonas,

    I've added a link to this blog post from the wiki.

    ReplyDelete
  2. Thanks for this post. It was a huge help for me.

    ReplyDelete
  3. Thanks! got this up and running in no time using the remote java debugger. Nice and easy to use.

    ReplyDelete
  4. I'm having a heck of a time trying to get the debugging to work for a basic cuke4duke example. I explain in detail here: http://groups.google.com/group/cukes/browse_thread/thread/4c0bb425cf78a9b4

    Any help would be greatly appreciated.

    ReplyDelete
  5. HAs anyone really managed to make the in-process debugging work?

    Following a vanilla install I am still finding this impossible - thinking now that my choice of this product was a mistake - debugging and other convenient IDE integration is essential.

    Luckily only written a couple of stories with this.

    Please help as this seems otherwise like a good product.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...