Debugging Cuke4Nuke Step Definitions

At a client today, we were doing some tricky automation with WatiN (against Telerik controls) in Cuke4Nuke. We wanted to dig into what WatiN was finding in the browser. The obvious move was to fire up the debugger. But with Cuke4Nuke, this is trickier than you might think. The Cuke4Nuke gem includes a release build—no debug symbols. Plus, the process isn’t around long enough to attach to if you use the cuke4nuke executable. We probably could have figured it out, but it wasn’t worth the trouble.

Since we weren’t debugging the Cucumber side of things, we didn’t need all the Cucumber and Cuke4Nuke plumbing. We just needed to run the code using WatiN.

NUnit and Resharper to the rescue…Cuke4Nuke cares about Given, When, Then, Before, and After attributes on your methods. But that doesn’t mean those are the only attributes allowed.

We added a TestFixture attribute to the class. We put SetUp and TearDown attributes on the Before and After methods. We created a new method with a Test attribute that called the relevant step definition methods. Set a breakpoint, click the Resharper test icon and choose Debug, and next thing we knew we were debugging our way through the step definition code.

Next time you need to debug a tricky step definition, don’t bother trying to get Cuke4Nuke in the debugger. Just use your unit test framework to call your step definitions. It’s faster to set up and faster to run.

Related Articles

Responses

  1. I’ve debugged tests with Cuke4Nuke by running Cuke4Nuke via Visual Studio. In the Server project settings I added the relevant command line arguments (in the Debug tab). F5 the server, then run cucumber separately. It’s fiddly since you have to find the right place to step into your test code. Not really a nice solution 🙂

    Could you add a debug flag to Cuke4Nuke? When it’s present it won’t run cucumber until some user action in the console. This would give time to attach a debugger to the process. What do you think? Seems like a slightly less hacky approach. I might give it a go one evening this week.

  2. @Luke – Good idea. I think debugging support should be built into Cuke4Nuke somehow, but I’m not sure exactly how. Right now, I don’t ship symbols in the gem, so just giving time to attach to the debugger only solves half the problem.

    If you come up with a good debugging solution, I’d be glad to pull it.

  3. @Stefan – Have you tried this in a Cuke4Nuke step definition? With Cuke4Nuke.Server.exe not having debug symbols and loading step definition assemblies via reflection, I wonder if it will work.

  4. My bad. You are absolutely right. It does not work. Despite the user defined breakpoint that is created by the call to Debugger.Break() the Cuke4Nuke server continues its execution and exits.

  5. 1. I added in step [Before] decorated method

    #if DEBUG
    Debugger.Break();
    #endif

    2. Then when I ran Cuke4Nuke … form command line I by OS that:
    “Application Server met breakpoint…”
    Then OS displayed a dialog named “Application Server has stopped working…” with “Debug” button

    3. Clicking on the button I was able to attach VS debugger to Cuke4Nuke.Server.exe

    4. Next I was able to debug what I wanted (including G/W/T parameters passed from features files)

    cuke4nuke: 0.4.0
    cucumber: 0.10.2
    ruby: 1.9.2
    OS: W7/64