Richard Lawrence

On making software teams happier and more productive

Debugging Cuke4Nuke Step Definitions

8 comments

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.

Written by Richard

January 12th, 2010 at 7:52 pm

8 Responses to 'Debugging Cuke4Nuke Step Definitions'

Subscribe to comments with RSS or TrackBack to 'Debugging Cuke4Nuke Step Definitions'.

  1. Very clever!

    Declan Whelan

    12 Jan 10 at 8:03 pm

  2. 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.

    Luke Smith

    13 Jan 10 at 6:25 am

  3. @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.

    Richard

    13 Jan 10 at 10:28 am

  4. I love this idea. The exact same approach can be taken with Cuke4Duke. I have linked to your article from here:

    http://wiki.github.com/aslakhellesoy/cuke4duke/debug-cuke4duke-steps

    Aslak Hellesøy

    13 Jan 10 at 5:21 pm

  5. Neat trick Richard!

    I think the way to build debugging into Cuke4Nuke would be to use the /DebugExe command-line switch for of VS: http://www.olegsych.com/2007/08/debugexe-command-line-switch-in-visual-studio/

    Matt Wynne

    14 Jan 10 at 12:13 am

  6. You can use Debugger.Break() in your .NET code when you want to break and attach a debugger.

    Stefan Dobrev

    31 Jan 10 at 11:40 am

  7. @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.

    Richard

    3 Feb 10 at 1:18 am

  8. 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.

    Stefan Dobrev

    4 Feb 10 at 12:53 pm

Leave a Reply