Skip to main content
Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

Discover Behavior-Driven Testing

Learning Objectives

After completing this unit, you’ll be able to:

  • Explain the purpose of behavior-driven testing.
  • Explain the features and common challenges of behavior-driven testing.

What Is Behavior-Driven Testing?

Behavior-driven testing (BDT) builds test cases on user behavior rather than data. Test cases follow the steps of the user experience to understand how users interact with an application and improve their experience with it.

To focus on the user experience, BDT brings together team members across business and operations, ensuring testing efforts are aligned with business objectives. Through this joint effort, all stakeholders can discuss and come to a consensus on business requirements.

As you learned in Quality Teams Across the Software Testing Lifecycle, a collaborative approach to quality often leads to an improved experience for end users. With an early consensus of business requirements, testing teams can better plan and execute their efforts, leading to earlier detection of defects and preventing frustration for users.

Creating Behavior-Driven Tests

Because BDT involves stakeholders from technical and non-technical teams, its scenarios need to be written in natural language for everyone to understand. As a plain-text language with a clear structure, Gherkin Syntax is the right fit for these teams to create their test cases. It uses the keywords Given, When, and Then to organize scenarios.

This table outlines a scenario for entering credentials to log in to a page.

Keyword

Purpose

Example

Given [a condition]

Set the context

Given I am on the Login Page

When [something happens]

Specify user action

When I enter the correct username and password

Then [result occurs]

Identify expected outcome

Then I should be taken to the Welcome Page

Scenarios are often more complex than three lines, and Gherkin Syntax accommodates this with additional keywords, including And when multiple actions need to be specified. Simple or complex, though, Gherkin Syntax’s structure creates clarity for the entire team.

People sitting around a long table in a meeting room planning their test strategy.

Common Challenges

While one of the greatest benefits of behavior-driven testing is its focus on the user experience, it is also one of its greatest challenges. With data-driven testing, the tests are only as good as the data. With BDT, the tests are only as good as the scenarios, and these require expertise and a culture of collaboration.

These efforts to learn about, test, and improve user experience take time. To begin, stakeholders need a firm understanding of the application. This means understanding not only how it works but also how users interact with it before being able to translate it into Gherkin terms.

On top of this, teams need to come to a consensus about prioritizing requirements. Collaborating in a productive and efficient way requires a strong team that can work well together.

Sum It Up

Data-Driven Testing is a more technical methodology designed to separate test logic from the data sources. Behavior-driven testing’s more collaborative approach uses natural language to frame its scenarios. In the end, the right testing methodology comes down to your resources and requirements.

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback