The document discusses Behavior Driven Development (BDT) using Microsoft Visual Studio 2010 and SpecFlow, including an overview of BDT, different BDT methodologies, using Gherkin syntax to write scenarios, configuring SpecFlow tests in Visual Studio, and a live demo of SpecFlow.
Confidential
GTC-NL for internaluse
Goal of presentation
⢠Informative
⢠Share my knowledge w.r.t. Testing and Test tools
In the scope of ādid you know?ā
Gathered in my daily train trips
Amstelveen Best
3.
Confidential
GTC-NL for internaluse
Qeustion 1: what are the following two vegetables?
Subject of today is related to some vegetables
Answer 1: Cucumber Gherkin
Question 2: What is the difference between the two?
Answer 2:
Cucumber: Tool, behavior driven development, ā¦
Gherkin: Language, Business Readable, Domain Specific Language,..
Let start with a Quiz
4.
Confidential
GTC-NL for internaluse
Content
⢠Behavior Driven Development (Development view)
ā Agile Iteration and Test Driven Development (TDD)
ā Whatās all these DDās? (TFD, TDD, BDD, ATDD and SDD)
ā Scenario/Story and Gherkin-syntax
ā Executable Specification
ā Behavior Driven Development tools
ā Live demo with SpecFlow
⢠Behavior Driven Testing (Test view)
ā DDB vs BDT
Confidential
GTC-NL for internaluse
ATDD
- Acceptance Test Driven
- Different than BDD?
- Start with the acceptance test
- Examples,
(2) Write the
implementation code to
make the test pass. Keep
it simple
(3) Change the code to
remove duplication in code
and to improve the design
while ensuring that all tests
still pass.
(1) Imagine how the new
code should be called and
write the test as if the code
already existed
7.
Confidential
GTC-NL for internaluse
What are the advantages of TDD?
⢠TDD shortens the programming feedback loop
⢠TDD provides detailed specification (tests)
⢠TDD promotes the development of high-quality code
⢠TDD provides concrete evidence that your software works
⢠TDD supports evolutionary development
⢠TDD encourages developers to write code that is easily tested
TDD is used in
Agile development
eXtreme programming
8.
Confidential
GTC-NL for internaluse
ATDD
- Acceptance Test Driven
- Different than BDD?
- Start with the acceptance test
- Examples,
Test First
Development
Refactor
TDD
Start from acceptation test
Focus on behavior of feature
S/BDD
9.
Confidential
GTC-NL for internaluse
Whatās all these DDās?
TFD Test First Development
TDD Test Driven Development
ATDD Acceptance Test Driven Development
BDD Behavior Driven Development
STDD Story Test Driven Development
TTD = Test First Development + Refactor (remove duplicate, improve design)
Micro view
ATDD start for end user acceptance test
Macro view
BDD focus on the behavior of the feature
Based on user story: a couple of examples on how SUT could be used
Story written in a standard syntax: e.g. Given / When / Then
The [Given, When, Then] syntax is called Gherkin
First create test (Failing test) than create implementation (Test passed)
10.
Given [initial context]
When[event]
Then [an outcome]
Subsequent steps of the same kind can also be specified with the āAnd ā and āButā keyword
11.
Variations on aTheme
Context
Specification
AAA
User Story
Structure
Establish
Initial Context
Given
Arrange
SetContext
Interact with
SUT
When
Act
BecauseOf
Check the
results
Then
Assert
ItShould
12.
Confidential
GTC-NL for internaluse
Example: Application Under Test
(3) Application displays āHello Best Tester: Password is Correctā
(If password = āRachidā)
(1) type password āRachidā
(2) press Login button
(0) start application
āSay Hello Best Testerā a simple application for demo purpose.
According req. of this tool: āRachidā, āAliā and āPieterā are correct passwords for login.
13.
Confidential
GTC-NL for internaluse
Example: Feature file (Scenarioās: Given When Then)
Feature: Log-In in āBest Tester Applicationā, check correctness of
password
Scenario: Check Login with correct password
Given Application is started
When correct password is typed
And Login button is pressed
Then Login should be successful
And Messagebox should display "Hello Best Tester: Password Correct"
Describe some piece of functionality of the system
Plain readable text
Features contain one or more scenarios
A scenario describes a single acceptance test for a feature
Most features are composed of multiple scenarios
Tool generates a test for each scenario
The name of the test is generated from the scenario title
14.
Confidential
GTC-NL for internaluse
When scenario/story is in place it would be wonderful if there is a
tool that can run this scenarioās to verify that the implementation
actually behaves as specified.
Executable specification that verifies that the implementation behaves as expected, readable by all in the team, and around it
Requirements
/Behavior
In well known
format
e.g.
Given/When/Then
Tool
Implementation
(SUT)
Main benefit
Main benefit is not in the tool!
The benefit is that team get together and write down a common,
shared knowledge in a well known format. In one place.
15.
Confidential
GTC-NL for internaluse
Tools
This was the idea of Cucumber tool that first was created in the Ruby-community.
Cucumber can execute scenarios written in the Given/When/Then-syntax.
For .Net framework SpecFlow is known good tool.
Both tools used Gherkin syntax and are free (open source).
Cucumber
Ruby
SpecFlow
.Net
16.
Confidential
GTC-NL for internaluse
Behavior Driven Development in one slide
Feature file
(Scenarioās: Given When Then)
Test class (for Nunit)
Generated by SpecFow tool (.cs)
Stepper class
binding with implementation (.cs)
Implementation
(.dll, .exe)
Nunit dll
Nunit
Test
report
Code of Implementation (.cs)
Visual Studio 2010 + SpecFlow
SW developer
Requirements
User
feedback1
2
3
4
5
6
7
8
17.
Confidential
GTC-NL for internaluse
Some handy Attributes
Background
With the keyword background you can run some steps before each scenario in the
feature.
Hooks
Hooks are events that is fired in the following order.
And you can āhook inā code here to do useful things:
- Restore a database
- Dump a log on error
- Init variables before steps
Scenario outlines
Data-driven scenarios or scenario templates
Consists of Scenario template specification with data placeholders
Tool generates parameterized test logic for the scenario outline and individual test
method for each example set (using pairwise testing)
18.
Confidential
GTC-NL for internaluse
Some handy Attributes
Tag
Can be used to specify ācategoriesā for Nunit or other test runners
e.g. @RegressionTestSet
@ignore tag is a special tag āignore testā
# is reserved for comment
#language
The language of the feature files can be either specified globally in the
configuration file or in the header of the feature file using ā#languageā keyword
different ISO languages are supported
Debugging Tests
SpecFlow Visual Studio integration also supports debugging the execution of the
tests. Just like in the source code files of your project, you can also place
breakpoints in the SpecFlow feature files. Whenever you execute the generated
tests in debug mode, the execution will stop at the specified breakpoints and you
can execute the steps one-by-one using the standard āStep Overā (F10)
command or you can go to the detailed execution of the bindings using the āStep
Intoā (F11) command.
Confidential
GTC-NL for internaluse
Behavior Driven Development in one slide
Feature file
(Scenarioās: Given When Then)
Test class (for Nunit)
Generated by SpecFow tool (.cs)
Stepper class
binding with implementation (.cs)
Implementation
(.dll, .exe)
Nunit dll
Nunit
Test
report
Code of Implementation (.cs)
Visual Studio 2010 + SpecFlow
SW developer
Requirements
User
feedback1
2
3
4
5
6
7
8
23.
Confidential
GTC-NL for internaluse
Behavior Driven Testing in one slide
Feature file
(Scenarioās: Given When Then)
Test class (for Nunit)
Generated by SpecFow tool (.cs)
Stepper class
binding with implementation (.cs)
SUT (FlashLite)
Nunit dll
Bello/Nunit
Test
report
Visual Studio 2010 + SpecFlow
Requirements
Tester SW/FW developer
implementation
code
Development
environment
User
SW/FW Implementation
feedback
4
2
3
1
5
24.
Confidential
GTC-NL for internaluse
http://www.synerzip.com/agile-method.htm
Behavior driven testing
Development domain
Test domain
25.
Confidential
GTC-NL for internaluse
BDD vs BDT
⢠Behavior Driven Development (BDD)
ā Development domain
ā White box
ā Micro view
ā Input = specification (Behavior)
ā Output = Implementation
⢠Behavior Driven Testing (BDT)
ā Test domain
ā Black box (interface)
ā Macro view
ā Input = Specification (Behavior)
ā Output = Test
26.
Confidential
GTC-NL for internaluse
Requirement Based Testing in one slide
Feature file
(Scenarioās: Given When Then)
Test class (for Nunit)
Generated by SpecFow tool (.cs)
Stepper class
binding with implementation (.cs)
SUT (FlashLite)
Nunit dll
Bello/Nunit
Test
report
Visual Studio 2010 + SpecFlow
Requirements
doc
SW/FW developer
implementation
code
Development
environment
User
SW/FW Implementation
feedback
4
3
2
1
5
Spec.doc to Feature file
convertor
(2) = refactor= clean up and improveTester
To be
developed
27.
Confidential
GTC-NL for internaluse
Learn more about SpecFlow and BDD
http://blog.dannorth.net/introducing-bdd/
http://www.specflow.org/
https://github.com/techtalk/SpecFlow
http://github.com/techtalk/SpecFlow-Examples
http://github.com/aslakhellesoy/cucumber/wiki
http://www.marcusoft.net/search/label/SpecFlow
https://github.com/marcushammarberg/
https://www.marcusoft.net
Free downloadable book
1, 2, 3
Given
When
Then
[TestMethod]
publicvoid
Total_Should_Be_1_When_1_Product_Added()
{
var cart = new ShoppingCart("TEST");
cart.AddItem(new Product("SKU"));
Assert.AreEqual(1, cart.TotalItems);
}