-
Notifications
You must be signed in to change notification settings - Fork 72
Debug Cuke4Duke Steps
An alternative to remote debugging is running the whole enchilada (JRuby, cuke4nuke, cucumber…) directly out of the IDE.
Based on Richard Lawrence’s technique for Cuke4Nuke we can annotate with JUnit annotations. An example of this can be seen in the WebDriver example.
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.
If you are using Ant the path to your cuke4duke
will be different, for example lib/.jruby/bin/cuke4duke
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.
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";
export MAVEN_OPTS
<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>