Do you want to share your content on R-bloggers? Click here if you have a blog, or here If you don’t.
When writing specifications, it is easy to get caught in implementation data, especially when adding specifications after the software has been built.
Let’s see how we can add specifications for existing code and get cucumber specifications that reflect business concepts instead of onion specialities that make expansion and maintenance easier.
The setup
Let’s introduce an app with a workflow as follows:
- The app opens on a “Data” page, with a stepper for: upload → filter → mapping → example.
- Upload users or select a standard datas set and then continue step by step.
- After submitting variable allocations, a data example appears.
- Once this is completed, a “visualization” function becomes available for viewing suddenly.
This workflow is fairly simple, but also quite complex.
Writing robust, feasible specifications for this requires that we express the logic without exposing underlying onion details.
1. Define behavior, not implementation
Switch away from the user interface or implementation -specific language. For example:
- Prevent:
Given the user starts on the Data page - Prefer:
Given the user begins a new data preparation session
This abstraction ensures that scenarios remain stable, regardless of changes in the user interface or technology stack. The scenario must apply equally well, whether the system is a web app, command line interface or something else.
2. Catch the current in Gherkin
Break the user down power down Core Business Steps:
- Start a new session for preparing data
- Enter a dataset (adjusted or standard)
- Optional Filters Apply
- Submit variable allocations
- View a data example
- Gain access to visualization
- View a plot
Concept scenarios using the Given – when – then Cadans to concentrate on results and user intentions instead of specific technical steps. This cadence is the fundamental BDD best practice, which improves clarity and maintainability.
Sample
Feature: Data visualization
This feature describes the core user flow for preparing a dataset
and accessing visualizations. The workflow includes optional and
required steps before plots can be viewed.
Background:
Given the user begins a new data preparation session
Scenario: User completes the workflow using a custom dataset
Given the user provides a dataset
When the user proceeds to the Filtering step
And the user skips filtering
And the user proceeds to the Mapping step
And the user accepts the default variable mapping
When the user submits the mapping
Then the user reaches the Preview step
And the dataset is available for inspection
And the Visualization feature becomes available
Scenario: User completes the workflow using a default dataset
Given the user chooses to use a default dataset
When the user proceeds through the Filtering step without applying filters
And the user accepts the default variable mapping
And the user submits the mapping
Then the user reaches the Preview step
And the dataset is available for inspection
And the Visualization feature becomes available
Scenario: Visualization is not available before data preparation
Given the Visualization feature is not accessible
When the user provides a dataset
And the user skips filtering
And the user accepts the default variable mapping
And the user submits the mapping
Then the Visualization feature becomes accessible
Scenario: User views a plot after completing data preparation
Given the user has completed the data preparation workflow
When the user accesses the Visualization section
And the user chooses to inspect Individual Plots
Then the user sees a visualization of the dataset3. View your specifications
- Avoid technical or user interface: Write steps as business actions, not click or onion navigation. For example, use “Submit the allocation” instead of “click on Send”.
- Use the right scenario structure: Always stick to the Given – when – then Cadans for clarity and consistency. Do not mix the order. To keep the scenarios readable, you can use alternative Steps Frasingen like “and” or “But”.
- In favor of high -level reusable steps: Steps as
the user provides a datasetorthe user submits the mappingare platform-agent and expandable. This makes function files easier to read, update and automate.
Repeat with AI
Use this prompt to help AI help you write pickle scenarios:
I'm adding Cucumber tests to an app. You're a BDD expert helping me discover business concepts and user flows. I will provide a description of how I interact with the app. Your task is to help me write executable specifications for given description. When writing specifications: - Don't reveal implementation details (like UI elements). - Imagine at least 3 different ways this system could be implemented, e.g. CLI, API, mind control. Those specifications need to be true no matter how the system is implemented. - Always use the Given–When–Then cadence. If something is not clear, ask me questions.
Starting with this prompt you can follow the process:
- Give a description of what you can do with the app.
- AI will introduce Girkin steps.
- View the steps and ask AI to build scenarios.
- View the scenarios and iter if necessary.
This can help you refine your specifications and ensure that they accurately capture the desired user behavior.
When working with AI, make sure that you do not accidentally reveal confidential information. Write your app description carefully.
Summary of the implementation data, especially if they already exist, is difficult.
But it is crucial for writing maintainable and expandable specifications. By concentrating on user behavior and results, you can make specifications that remain relevant, even if the underlying technology evolves.
And with the help of AI you get a new perspective on your application, which can lead to the creation of better specifications.
Related
#write #cucumber #specifications #app #description #scenarios #RBloggers


