Debug Cuke4Duke Steps

aslakhellesoy edited this page May 25, 2011 · 18 revisions

Sometimes you may want to set a breakpoint in a step definition or the application code. There are several approaches to achieve this.

(You may want to check out Jonas Bandi’s blog post which has some additional information).

Running from the IDE

An alternative to remote debugging is running the whole enchilada (JRuby, cuke4nuke, cucumber…) directly out of the IDE.

Run step definitions as JUnit tests

Based on Richard Lawrence’s technique for Cuke4Nuke we can use step definitions straight from a JUnit test. You can see an example of this in the WebDriver example.

(If your step definition classes have empty constructors you can annotate the step definitions directly as described in Richard’s article).

The whole enchilada

In Eclipse this is accomplished with a new Debug Configuration. Choose Java Application then configure it accordingly. For example, if you’re using Maven:

  • Main class: org.jruby.Main
  • Program Arguments: ${M2_HOME}/repository/.jruby/bin/cuke4duke ./target/test-classes features
  • VM Arguments: -Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.PicoFactory
  • Classpath: Make sure all needed jars are on the classpath.

An illustrated explanation of the aove setup in Eclipse can be found in this blog post.

If you are using Ant the path to your cuke4duke will be different, for example lib/.jruby/bin/cuke4duke

Remote debugging

To use enable debugging within cuke4duke is really easy. All you have to do is to enable remote debugging in the JVM using this jvm options:

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000

When you run cuke4duke (e.g. with maven or ant) this message will appear in the terminal:

Listening for transport dt_socket at address: 4000

All you have to do now is to place breakpoints in the code and launch the debugger.

Using Maven

If you’re using Maven the jvm options could be added in two ways:


MAVEN_OPTS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000";

Add a jvmArg to the pom.xml


Another alternative could be to replace the <jvmArg> with a property, <jvmArg>${cucumber.debug}</jvmArg>, that’s declared empty, but overridden by a maven profile.