Import and Create Test Cases Using BDD Feature File

Import and Create Test Cases Using BDD Feature File

Introduction

QTM4J supports importing test cases via a BDD feature file. It is an effective approach to ensuring software behaves as expected while fostering clear communication and collaboration among all team members. By using Gherkin syntax in feature files, teams can write tests that are simple to understand, easy to maintain, and straightforward to execute, resulting in a seamless and efficient testing process.

Benefits of Using BDD Feature Files to Import Test Cases

  • Improved Collaboration: Writing tests in plain language fosters better collaboration between business analysts, developers, and testers. Everyone can understand the tests, regardless of their technical expertise.

  • Clear Specifications: Feature files provide clear and concise documentation of the expected system behavior. These can serve as living documentation that evolves alongside the software.

  • Automation: Once the feature files are defined, they can be used for automated regression testing, ensuring the system continues to behave as expected over time.

  • Reduced Miscommunication: Because the tests are written in natural language, misunderstandings and miscommunications between stakeholders are minimized.

  • Test Reusability: Steps defined in feature files can be reused across multiple scenarios, leading to cleaner and more maintainable tests.

Pre-requisite: To display the BDD section on the Story issue page in Jira, the BDD Panel option should be enabled in the Project Settings. Refer to BDD in QMetry Test Management for Jira (QTM4J) for more details on configuring BDD and enabling the BDD panel.

→ Required Permissions: The following table shows permissions required to perform the corresponding operations.

Operation

Required Permissions

Operation

Required Permissions

Import Test Case

  • Import permission

  • Test Case View

  • Test Case Create

  • Test Case Edit And Archive

Update Test Case

  • Test Case View

  • Test Case Edit And Archive

Link Test Case

  • Test Case View

  • Test Case Edit And Archive

Link Requirement

  • Test Case View

  • Requirement View

  • Requirement Edit

Add Labels

  • Configuration View

  • Configuration Modify

Parameter

  • Configuration View (for reusing existing parameters)

  • Configuration Modify (for creating new parameters)

Business Rules

  • The files with the following attributes are supported:

    • Format: .feature files

    • File Size: Files with a total size of up to 10 MB, with each file having a maximum size of 1 MB

    • Limit of Number of Files: Individual files up to a maximum 10 files

  • Test Cases can be reused using the Test Case Key. The latest version of the test case that matches the Test Case Key will be updated.

  • Requirements can be linked to test cases using the Story Key. The test case version will be linked to the mentioned Story Key.

  • When the feature file is imported from the Test Case list view, the Examples in the feature file will become the @Parameters in steps and variables will become Parameters.

  • The feature has been tested exclusively within the Cucumber framework.

  • To know more about the guidelines followed for parsing the file, refer to Reference | Cucumber.

Mapping of Feature File with QTM4J Fields for Import

The following table displays the mapping of the feature file with QTM4J fields.

Scenario

QTM4J Test Case Mapping

Example/Note

Scenario Name

Test Case Summary

NA

Feature Name

Description

NA

Steps

Test Steps

Includes Keyword and Step

Data Table in Steps

Steps Summary

| username | password |

| validUser | invalidPass |

| invalidUser | validPass |

| validUser | validPass |

Docstrings in Steps

Steps Summary

"""

{

"username": "validUser", "password": "validPass"

}

"""

Tags

Labels

 

The tags at the Feature File level and at the Scenario/Outline level will be added as labels.

@testcasekey

Test Case Key

When importing the feature file, test cases can be reused by adding an annotation to the file.

  • If the specified key exists in QTM4J, the test case will be updated with changes in the feature file.

  • Multiple test case keys (i.e. testcasekey) can be defined for a single scenario, which will update/create multiple test cases for that single scenario. For example, the test case keys can be mentioned in tags as follows.

image-20241216-073550.png

@storykey

Jira Requirements

When importing the feature file, existing Jira stories can be reused by adding an annotation to the file.

  • If the specified Story Key exists in Jira, the test case will be linked to that Story.

  • The Story Key for cross-project is also supported during import.

  • The story linkage depends on the level at which the Story Key is mentioned:

    • Feature Level: All test cases created from the scenarios will be linked to the story.

    • Scenario Level: The test case that is created from the scenario will be linked to the story.

  • If the Story Key is invalid or not found, the Story linkage will not happen.

  • Multiple story keys (i.e. storykey) can be defined to link with the test case. For example, the story keys can be mentioned in tags as follows.

image-20241216-072208.png

Background Steps (Scenario Level)

Steps

These Background steps will be added as initial steps of the test case created from the scenario.

Background Step (Feature File Level)

Steps (i.e., initial steps of all test cases)

These Background steps will be added as initial steps of all the test cases created from the scenarios under the Feature.

Rule

Description

The first line of the Rule will be appended to the Description of the test case along with the Feature name separated by a semicolon ( ;).

Examples (Scenario Outline)

Parameters

Examples will become the @Parameters in Steps.

Variables will be Parameters in Test Data.

If duplicate parameter values exist in the .feature file, they will be created as a single value under Configuration > Parameters and will be reused under Test Case > Steps tab > Parameters section.

Sample Files

Sr. No.

File Content

Download Sample File

Sr. No.

File Content

Download Sample File

1

Feature File with multiple scenarios

2

Feature File with Scenario Outline

3

Feature file with Scenario and Scenario Outlines

4

Feature file with Rule, Rule Example Cases

5

Feature file with Rule, Scenario Cases & Background

6

Example for Table Data and Doc String

Best Practices

The following are some of the best practices for writing BDD feature files to import test cases, which help you ensure clarity, maintainability, and reusability of your BDD test cases.

  • Use Scenario Outline for data-driven tests with multiple input sets via Examples.

  • Keep scenarios focused on one behavior per test case.

  • Use clear, descriptive names for features, scenarios, and steps.

  • Group related scenarios together and use Background for shared steps.

  • Tag scenarios (e.g., @smoke, @regression) to label and categorize tests.

  • Write from the user’s perspective using simple, understandable language.

  • Ensure scenario independence to improve test reliability.

  • Refactor regularly to keep feature files clean and maintainable.

Feature Availability

You can access the feature from the following modules and pages:

Import Feature File

Import Feature File in Test Case Module

Testers can import test cases from the BDD feature files, where each Scenario or Scenario Outline or Example in the feature file represents an independent test case.

Steps

  1. Go to the Test Case module.

  1. Open the Import drop-down menu and select the Feature File option on it.

image-20241121-055438.png

The Import Test Cases from the Feature File screen opens.

  1. Open the From Feature File tab.

  1. To upload the .feature file, either select the file by clicking on the link or drop the file to the designated area.

image-20241217-065002.png

One record is added once the .feature file gets attached.

All the system and custom fields are displayed on the screen.

  1. Import Settings: Define the test case fields and set preference for the import options for the Test Case Key and Labels.

  • Select Test Case Fields: The Summary, Description, and Steps will be imported from the feature file. Select values for other system fields and custom fields on the screen.

Note: The selected fields will be applied to all test cases created from the feature file. The selection will be saved for future imports.

  • Import Options: Select the appropriate behavior for the given options.

    • If a Test Case Key is found for a scenario

      • Update current version

      • Create a new version

    • Tags will be imported as labels. If labels are not found.

      • Create

      • Ignore

  1. Click on the Import button.

image-20241217-065236.png

 

View Import Progress

Open the Test Case Import/Create Background Jobs tab.

You can see the record is added for the recent feature file import.

The details include Batch Id, Source, File Name, Status, Import Date, and Imported By. Expand the record to view the details of Scenarios imported during the operation, Test Case Keys to which the scenarios were mapped, version, and Status.

image-20241213-100315.png

Verify Created Test Cases

In the Test Case module, you can see the scenarios are imported as test cases in the folder you selected while importing the feature file. The scenarios will be imported to the root folder if a specific folder is not selected.

image-20241121-080602.png

See Also,

Create and Update Test Cases Using Feature File