Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

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:

Add MAVEN_OPTS

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

Add a jvmArg to the pom.xml


<plugin>
  <groupId>cuke4duke</groupId>
  <artifactId>cuke4duke-maven-plugin</artifactId>
  <version>0.1.9</version>
  <configuration>
    <jrubyHome>${env.JRUBY_HOME}</jrubyHome>
    <jvmArgs>
      <jvmArg>-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000
       -Xdebug</jvmArg>
      ....

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.


<profile>
  <id>cukes_debug</id>
  <activation>
    <property>
      <name>env</name>
      <value>cukes_debug</value>
    </property>
  </activation>
  <properties>
    <cucumber.debug>-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000
    -Xdebug</cucumber.debug>
  </properties>
</profile>

Clone this wiki locally