In the last few years, behaviour-driven development has entered my consciousness. Robert ‘Uncle Bob’ Martin was probably the first one. His videos introduced me to his FitNesse.
I tried to get it to work with a recent version of Java, but it fails in ways I don’t understand. I don’t have the motivation to track it down.
Then I came across Cucumber and Gherkin. The simplicity of getting it to work, the flexibility, and the fact it works so well with Source Control made it feel like a breath of fresh air.
Write tests in Gherkin, try them out, get them working, and repeat. That makes a nice short reward loop, motivating me to move forward in my program.
“When the rewards are too far away, the motivation to stay focused is low.”
Recently, I’ve been trying to figure out how to automate ticketing. Consider a GitHub issue: https://github.com/alesgaroth/juv/issues/1. I wrote up some Gherkin to describe what I wanted to happen.
If I wrote up enough Gherkin to describe what I wanted completely, I would know that the ticket could be closed when all of those tests passed.
If my build system could read the Gherkin out of the ticket and check that all those tests passed, it could close the ticket for me without me having to do it manually.
If my monitoring system could read the Gherkin and set up automated tests against production to monitor if it’s working correctly, I wouldn’t have to worry about it anymore.
For that matter, I could run a script to copy the Gherkin Scenarios from the ticket into a local .feature file, check it in, and mark it as “In Progress” when I wanted to start working on it.
My workflow as a developer would then be:
- Choose a ticket
- Run the script with the ticket number
- Make each test pass
- Create Pull Request
- Code Review responses
- Merge to main
I wouldn’t have to fiddle with the ticketing software, remembering to close it or move it to In Progress instead of:
- Choose a ticket
- Mark it as In Progress
- Figure out what tests to write
- Make each test pass
- Create a Pull Request
- Code Review responses
- Merge to main
- Verify it works when it hits production
- Close the ticket
That’s the ideal process. Usually, it turns into something like this:
- Choose a ticket
- Write some code to see if I can figure out how to do it.
- Open a Pull Request
- Right, I need a ticket. Let’s open the ticket
- Right, I need tests. Quick write some tests
- Weird, I found a bug while writing the tests.
- Make each test pass
- Code Review responses
- Merge to main
- At standup, mention that I already had it merged days ago, and watch the presenter close it for me.
Having some of that automated away would make it less intimidating and naturally help me keep the order.