Behave – Introduction

Behave - Introduction

In this topic, we shall discuss in detail Behave Introduction. This Behave is a Behavior-driven development (BDD) tool in Python language. This topic shall provide you with a piece of detailed knowledge of Behave and its different terminologies.

Audience

This contains a good amount of illustrations on all important topics in Behave.

Behave Introduction

Behave is a tool used for Behaviour driven development (BDD) in the Python programming language. In an Agile development framework, BDD creates a culture where testers, developers, business analysts, and other stakeholders of the project can contribute towards the software development.

In short, both technical and non-technical individuals have a role to play in the overall project. Behave has tests developed in plain text with the implementation logic in Python.

The BDD format begins with the description of the characteristics of the software similar to a story.

It then continues with the development and carries out the following tasks โˆ’

  • Developing a failing test case for characteristics.
  • Implement the logic for a test to pass.
  • Code refactor to fulfil the project guidelines.

There are numerous libraries for BDD like the Mocha which supports JavaScript, Cucumber which supports Java/Ruby, and Behave which supports Python, and so on.

In this tutorial, we shall discuss in detail Behave.

Let us see a basic structure of a BDD. It mainly consists of the feature film, the step definition file, and so on.

Feature File

The feature file in Behave can be as follows โˆ’

Feature โˆ’ Verify book name added in Library.
Scenario โˆ’ Verify Book name.
Given โˆ’ Book details.
Then โˆ’ Verify book name.

Corresponding step definition file

Following is the corresponding definition file in Behave tool โˆ’

from behave import *
@given('Book details')
def impl_bk(context):
   print('Book details entered')
@then('Verify book name')
def impl_bk(context):
   print('Verify book name')

Output

The output obtained after running the feature file is as follows โˆ’

Behave - Introduction

The output shows the Feature and Scenario names, along with the test results, and the duration of the respective test execution.

Next Topic – Click Here

This Post Has 12 Comments

Leave a Reply