A glance at BDD, my Cucumber adventure

Quickly after joining my team, I learned about the Javascript testbot that works but somebody left to slowly be forgotten. Once granted time, the team looked into refactor the artifact using Cucumber as the new default tool to conduct and run automated integration testing with.


cucumbers


How can you use Cucumber?

Cucumber is a testing tool that supports behavior-driven development(BDD), enabling users to define and run automated tests based on Gherkin syntax. What is Gherkin you might wonder?
It is a language which aim to describe the behavior of code in a way that is easy to understand(plain text) without the requirement of technical knowledge. My team uses Java but Cucumber can be used with various other programming languages, like Ruby or Javascript.


Tags


In Cucumber you can use @Tags to enable automated testing, associate certain scenarios and features which then can acts as triggers in scheduled test suites or during deployment processes. We use them both as execution triggers and configuration setup in conjunction with the “Before” and “After” step hooks.


tags


This picture show both types of tags, @VehicleApp trigger the feature during the components build step and @SqueedHourly is a scheduled testing suite which runs every hour.
The @Vehicle_GDPR_Report, and @European_Brand ones serves as identification for which configuration will take precedence during the given scenario. This allows you to easily reuse your step definitions and prevent step files from being bloated.


Background


Before both the scenarios in this feature you find a “Background”-paragraph. These are a great way to gather step definitions which are shared and they will run before every scenario since they are used by more than one.


Anti Patterns


Try to refrain from creating these patterns

  • Feature coupled or feature specific step definitions, they will cause code duplication
  • Conjunction steps, there is a reason they created “And” or “But”. Can you find my blunder?
  • No clear separation between “Given”, “When”, “Then”, describe the context, the action, and the outcome.


Scenario Outline


This particular feature runs API security checks on a longer interval based on the @SqueedDaily tag. This Scenario will run the same test case with different values.
If you have worked with Java and JUnit 5 you might recognize the similarities to the “Parameterized Tests”, it is a great way to dynamically feed test data to a single test case.


scenario-outline



Cucumber test result


This is after one “Security Access Control” execution, here is where you can revisit all tests cases and find out their result, execution time, errors and report information.


test-results



What I like about Cucumber

  • Run quick and scheduled automatic testing suites
  • Generate reports based on tested features and system behavior
  • Easily prepare systems and data for load test
  • Conduct initial troubleshooting without programming knowledge


Before leaving the team, one of my senior colleagues left me with a great gift and idea. Prior to decommissioning the old testbot, we used it for load testing but we had to keep track of a various tools, execute python scripts in sequence to update required data and align system processes.

With Cucumber we can instead utilize Scenarios and Steps to easily prepare and configure the system from one place. Since our system is scheduled for load testing once every Program Increment, implementing a “one-click load test preparation” will be my next endeavor.


If you have any great ideas on how to use Cucumber, feel free to contact me - I’d love to learn more!


Cucumber Documentation - Docs Homepage
Cucumber Anti-Patterns - Think Code Blogpost

Feel free to browse more posts from other Squeeders in our - Christmas Calendar 2023


general-tech-picture



Todo’s

The current main goal is to take care of our newborn - we are still trying to find our routines every day.

Call to papers has been announced for our upcoming internal conference SqueedBrew Tech 2025.
This year’s talk was a mix of topics of which I’ve stumbled upon last two years SqueedBrew Tech 2024.

Here are the latest updates from my backlog, detailing stories and their status at the moment.

Hobby projects

[ - ] Plan for future journal entries - In progress, I have amassed a lot of interesting topics - time to do work!
[ - ] Finish Tekk-Fungi-Feed component - In progress, major rewrite of learning journal with Minima V3.
[ - ] Revisit Tekk-Mycelium-Maestro - In progress, glanced att implementing a WAF, more work than planned.
[ x ] Refactored GitHub Pages - Done, there are always more stuff I can add but at least now we have a starting point.

Activities

[ x ] Visited “Botaniska Trädgården” - Done, I have been longing to visit since we moved here, I miss Gardening!
[ - ] Started going out more - In progress, our daughter is growing, and we cautiously introduces more public spaces.

Food

[ x ] Made another pizza dough - Done, tried another oven setting and crust got crispier, overall better.
[ x ] Surprise my fiancé with a “Kräftskiva” - Done, it was great, but we overdid it in terms amount of food.

Reading

[ - ] Finish L’Abbé C by Georges Bataille - Paused, still no progress, reading AWS Well-Architected Framework instead.
[ x ] Push forward AWS Developer exam to October - Done, since it is on discount, I will take Solutions Architect as well.
[ - ] Schedule AWS Solutions Architect exam in November - In Progress, worth a try since the exams have some overlap.
[ x ] Read chapter in “Modern Software Engineering” - Done, I chose chapter 4, “Working Iteratively”, will discuss in entry.

Training

[ - ] Running, Gym, Yoga, Bouldering - Paused, trouble getting out, I aim to at least get a 10-minute walk after each meal.


Thank you for your time, follow as I continue to explore and document my journey.

Take care!