AWS Logo
Menu
Q-Bits: Integration Testing with Gherkin + Amazon Q Developer

Q-Bits: Integration Testing with Gherkin + Amazon Q Developer

Learn how to use a standardized prompt file to generate Integration Tests with Gherkin

Abhi Bhattacharya
Amazon Employee
Published Jan 15, 2025
Welcome to another installment of Q-Bits, our regular series showcasing cool ways Amazon employees are leveraging Amazon Q Developer.
Today we are looking into how to use a standardized prompt file to generate Gherkin based Integration Tests.

Introduction

As builders we need to create Integration Tests to validate how our application behaves. One of the popular ways is Behavior Driven Design (BDD Tests) using Gherkin.
In this article, I will guide you through the process of using a standard prompt to generate scenario based tests using Gherkin and Cucumber for a Java project.

Why Use Standard Prompt

Prompt Engineering is an important part of any GenAI based application and the same rules apply to Amazon Q Developer. There is a trend towards standardizing commonly used prompts and using it as a re-usable component across enterprise projects. One such effort is shown in this blog; here we use a standardized prompt file to create Gherkin based tests.

How to use standardized prompts

  • Save the above prompt in a Markdown (.md) or Text (.txt) file in your project workspace.
  • Run @workspace in the Amazon Q Developer Chat window to index your workspace.
  • Refer to the prompt file along with additional context information in the Amazon Q Developer Chat to prompt the desired output.
Let's see how we implement these steps.
1. I am saving the above prompt in a folder called prompts in my project workspace with the name P-GHERKIN.md
Save Prompt in a markdown file with extension .md
Save Prompt in a markdown file with extension .md
2. I run @workspace to index my local workspace. This indexes all the files in my project workspace including the Prompt file I created in Step 1.
Use @workspace to index the project workspace
Use @workspace to index the project workspace
3. Refer to the Prompt file to generate test for a scenario. In this example, I will generate test for the Product flow.
Prompt -
@workspace use the prompt in P-GHERKIN.md to generate integration test for the Products flow
Tell Amazon Q Developer to refer to the prompt in P-GHERKIN.md to generate integration test.
Tell Amazon Q Developer to refer to the prompt in P-GHERKIN.md to generate integration test.
Generated Output -
1. Feature file for Products generated:
Feature file for Products Scenario
Feature file for Products Scenario
2. Test implementation using Spring Boot Test framework generated:
Test implementation using Spring Boot Test framework
Test implementation using Spring Boot Test framework
3. Test Configuration generated:
Test Configuration
Test Configuration
4. Test Data Configuration generated:
Test Data Configuration Generation
Test Data Configuration Generation
5. Dependencies for pom.xml generated:
Dependencies for pom.xml
Dependencies for pom.xml
6. Test Runner generated:
Test Runner generated:
Test Runner generated:
7. How to run the tests and summary generated:
How to run the tests
How to run the tests

Conclusion

In this post, I have explored two aspects -
  1. Creating and using standard prompt files across projects for commonly occuring workflows.
  2. Use such a standard prompt file to generate end to end code for a business flow.
Using the above two principles, we gain efficiency and leverage Amazon Q Developer features to the maximum extent.
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

1 Comment