Behavior-Driven Development

in 5 minutes

TL;DR

  • articulate "what to build"
     
  • collaborate across product/dev/QA
     
  • write specifications in Gherkin
     
  • have specifications/tests/documentations

BDD vs. TDD

TDD is a developer's practice

"How to build?"


BDD is a collaborative practice

"What to build?"

Articulate "what to build"

Collaborate across teams

User story: task creation

As a clinician,
 

I would like to create task for a patient and assign to clinicians,

so that remaining operations for that patient can be tracked.

User Story

Specifications: task creation

Feature: Task Creation

  Clinician can create task for a patient, and assign to multiple clinicians.

  Background: Clinic is staffed
    Given Care group "AKIRA-CC"
    And Clinician Claire is in care group "AKIRA-CC"
    And Clinician Carol is in care group "AKIRA-CC"

  Scenario: Task creation with single assignment
    Given Patient Peter is in care group "AKIRA-CC"
    When Claire creates a task for Peter
    And Claire assigns task to Claire
    Then Task should be open
    And Task is assigned to Claire
task_creation.feature

Step definitions: task creation

Given('Clinician {word} is in care group {string}') do |clinician_name, care_group|
  care_group = @care_groups[care_group]
  @clinicians[clinician_name.downcase] ||= FactoryBot.create(:medical_doctor, care_group: care_group)
end

When('{word} creates a task for {word}') do |clinician_name, patient_name|
  clinician = @clinicians[clinician_name.downcase]
  patient = @patients[patient_name.downcase]
  @task = FactoryBot.create(:task,
                            patient: patient,
                            author: clinician.user
                           )
end

Then('Task should be {word}') do |expected_status|
  expect(@task.refresh.status).to eq(expected_status.downcase)
end
task_steps.rb

Cucumber output (console)

Cucumber output (HTML)

BDD example:

task acknowledgement

See reference at end

BDD & TDD

Key takeaways (again)

  • articulate "what to build"
     
  • collaborate across product/dev/QA
     
  • write specifications in Gherkin
     
  • have
    • executable specifications
    • automated tests
    • living documentations

References

Thank you!

BDD in 5 minutes

By Dapeng Li

BDD in 5 minutes

  • 123