TestOptimal Tutorials

Behavior-Driven Testing (BDT)

Behavior-Driven Testing (BDT)
with TestOptimal

This tutorial will cover:

  • Why TestOptimal BDT?
  • BDT Notation
  • BDT Development Process
  • BDT Scripting
  • Test Execution & Debugging
  • Transform BDT to MBT

Why TestOptimal BDT?

  • BDT is a component of BDD (Behavior-Driven Development)
  • TestOptimal BDT IDE provides an integrated environment for:
    • Developing scenarios
    • Building automation
    • Embedded Data-Driven Testing
    • Integrated Combinatorial & Pairwise Testing
    • Interactive test execution
    • Full feature debugging
    • Automating various types of AUT
    • Re-purposing test suites for load testing
    • Transform BDT suites to MBT models

press down arrow for feature details

Why TestOptimal BDT?

  • Additionally you can also integrate your BDT test suite with:
    • other test automation tools
    • requirement source/systems
    • defect tracking systems

press down arrow for feature details

Why TestOptimal BDT?

BDT Notation

  • Test scenarios are designed to test AUT behaviors
  • Scenarios are grouped into Features
  • Each scenario consists of:
    • GIVEN
    • WHEN
    • THEN

press down arrow for feature details

BDT Notation

Example of BDT suite:

// BDT Test Suites for Vending Machine
FEATURE Purchase Drinks with Coins {
  SCENARIO Purchase A Coke with Quarters {
    GIVEN Zero Balance 
    WHEN I deposit 4 Quarters and choose Pepsi
    THEN It should dispense Pepsi 
  }
  SCENARIO Purchase A Coke with HalfDollar Coins {
    GIVEN Zero Balance 
    WHEN I deposit 2 HalfDollar coins and choose Water
    THEN It should dispense Water 
  }
}
FEATURE Purchase Drinks with Credit Card {
  SCENARIO Purchase A Coke with VISA {
    GIVEN Zero Balance 
    WHEN I swipe VISA card and choose Coke
    THEN It should dispense Coke 
  }
}
						
								
							

press down arrow for feature details

BDT Development Process

5 Easy Steps to Develop BDT Suites:

  • Identify feature sets to test
  • Create scenarios to test each feature
  • Add test automation scripts
  • Execute & debug test suites
  • Review test results

press down arrow for feature details

BDT Development Process

Identify feature sets to test:

  • Identify features from:
    • functional requirements
    • non-functional requirements
    • user stories
    • business use cases
  • Describe features in plain English
  • Optionally assign a short unique identifier to each feature
  • IDs are used as labels on test visualization

press down arrow for feature details

BDT Development Process

Identify feature sets to test:


FEATURE Purchase Drinks with Coins | id=CoinsForDrink {
}
FEATURE Purchase Drinks with Credit Card | id=CreditForDrink {
}
						

press down arrow for feature details

BDT Development Process

Create scenarios to test each feature:

  • Create scenarios to exercise feature
  • Explore different variations
  • Each scenario must contain 3 steps:
    • GIVEN - setup for the scenario
    • WHEN - actions to exercise scenario
    • THEN - expected AUT behavior
  • Describe scenario and steps in plain English
  • Optionally assign unique identifier to each scenario and step

press down arrow for feature details

BDT Development Process

Create scenarios to test each feature:


FEATURE Purchase Drinks with Coins | id=CoinsForDrink {
  SCENARIO Purchase A Coke with Quarters | id=QuartersForCoke {
    GIVEN Zero Balance {
    }
    WHEN I deposit Quarters and choose Pepsi | id=QQQ_Pepsi {
    }
    THEN It should dispense Pepsi {
    }
  }
}
						

press down arrow for feature details

BDT Development Process

Add test automation scripts:

  • Add automation to each scenario step using MScript
  • MScript is a simple scripting language similar to javascript
  • MScript is used:
    • Retrieve data for data-driven testing
    • Interact with AUT (test automation)
    • Perform verification and validation
    • Record/audit test execution

press down arrow for feature details

BDT Development Process

Add test automation scripts:


SCENARIO: purchase a Pepsi with Quarters | id=BuyPepsiWithQQQQ {
  GIVEN: Zero Balance {
    $log('Scenario: $curScenario()');
    $Selenium.click('id=cancel');
  }
  WHEN I deposit [Quarter]s and choose [Pepsi] | id=QQQ_Pepsi {
    $callFunc('buyADrink');
  }
  THEN: It should dispense [Pepsi] | id=dispenceDrink {
    $callFunc('assertDrink');
  }
}
						
  • Notice step description is tokenized for automation purpose
  • Add MScript to each scenario to perform appropriate automation

press down arrow for feature details

BDT Development Process

Execute & debug test suites:

  • Run test suites right from the IDE
  • Test suites can also be executed on dedicated QA server
  • Same test suites can be combined for load testing

press down arrow for feature details

BDT Development Process

Review test results:

  • Test failures are marked on MScript lines
  • Test execution stats are automatically stored
  • Details of test executions can be reviewed
  • Historical test executions are summarized for trend analysis
  • Key Performance Indicators (KPI) are automatically updated

BDT Scripting

Scripting with MScript:

  • There are 3 simple statements in MScript:
    • if
    • while
    • function calls

press down arrow for feature details

BDT Scripting

Scripting with MScript:


$setVar('coinType','$whenTokenByIdx('1')');
$setVar('drinkType','$whenTokenByIdx('2')');
if ([coinType] eq Quarter) {
  $setVar('coinNum', '4');
}
if ([coinType] eq HalfDollar) {
  $setVar('coinNum', 2');
}
while (true | maxLoop=[coinNum]) {
  $click('xpath=id(\'add[coinType]\')');
}
$click('id=[drinkType]');
						

press down arrow for feature details

BDT Scripting

Scripting with MScript:

  • There are hundreds of pre-built MScript functions:
    • System functions
    • Plugin functions
  • Create your own MScript functions

Test Execution & Debugging

Execute test suite by:

  • click on - normal execution
  • click on - animate execution
  • click on - debug execution
  • send http/REST command from your CI server

press down arrow for feature details

Test Execution & Debugging

Debug execution:

  • Run entire test suite or just specific scenarios
  • Pause execution
  • Set breakpoints
  • Step through MScript
  • Monitor user and system variables
  • Check data set usages
  • Dynamically interact with AUT

Transform BDT to MBT

BDT Suites are basic MBT models:

  • Ready to be enhanced to full-feature MBT models
  • Can use MBT sequencers to exercise scenarios for different usage pattern
  • Can be orchestrated with Load Models for load and performance testing

press down arrow for feature details

Transform BDT to MBT

Auto-Generated MBT Model from BDT Suite:

In Conclusion

TestOptimal BDT provides:

  • Flexibility and Agility of BDT
  • An Upgrade Path to Powerful MBT
  • Ability to Leverage BDT Suites for Load Testing

THE END

Visit other tutorials Here

© TestOptimal LLC.