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.