Date post: | 28-Mar-2015 |
Category: |
Documents |
Upload: | carina-loos |
View: | 217 times |
Download: | 2 times |
119-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Brown Bag – Behaviour Driven Development with Specflow
Brown Bag – Behaviour Driven Development with
219-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
What is BDD?
BDD changes the way we define and document software and helps us to think more about how our software behaves than how it is structured.
Behaviour Driven Development is an Agile process that comes from TDD that allows teams to define tests upfront in common business language.
319-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Benefits of using the BDD process
• CommunicationIncreases communication and understanding within and outside of the team
• ClarityDrives out ambiguities in stories early before valuable coding time is used up
• DocumentationGives specification by example – living documentation which can be shared to downstream systems
• Business ledFunctionality is driven by the business and has to conform to acceptance criteria
• TestableEnsures functionality is testable providing robust code. Get integration and regression testing for free.
• Progress indicatorInstant feedback of development progress as tests pass
• Instant feedbackTests and results are transparent at code check in and bugs identified immediately.
• Reduces supportReduces support by reducing bugs and misunderstanding of requirements. Documentation can be used to reduce support.
• Increased confidenceLiving documentation can highlight large test coverage with passing tests to downstream teams and gives developers confidence to make large changes knowing the interfaces have not been broken.
419-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Installing SpecFlow
• We will cover SpecFlow which is a free add-on for Visual Studio.http://www.specflow.org/
• SpecFlow can use any test runner – (Tested with MSTest and NUnit)
Install SpecFlow
1. Add SpecFlow in Visual Studio through the Extension Manager
2. Add SpecFlow NuGet package to your test project 3. Add a feature file to your project
519-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Feature Tests
As new features are added, we write tests around each feature. Tests are grouped by feature.
619-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Structure of a feature
Feature tests are written in the format:Given -> When -> Then
Given is the set up of the existing state before the test
When is the action I am testing
Then is the result I expect to get back
Example of a test for a feature
719-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Structure of a feature
The C# framework code is auto-generated Right click and ‘creating step definitions’ to allow SpecFlow to generate the C# methods for developers to write wiring code into.
Auto-generate C# method stubs
819-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Structure of a feature
The C# framework code is auto-generatedThe auto-generated method stubs are complete but basic. Additional steps are required for best practices and code re-use.
Auto-generate C# method stubs
Stock ticker can be a variable to allow test re-use
Variable names should be more descriptive
919-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Structure of a feature
The C# framework code is auto-generatedThe auto-generated method stubs are complete but basic. Additional steps are required for best practices and code re-use.
Change hard coded string to wild card
Rename variable and add stock ticker variable
1019-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Structure of a feature
Feature file is colour coded
Variables are a different colour
Test font colour is now black as there are matching code stubs
1119-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Structure of a feature
Feature file is colour coded
Variables are a different colour
Test font colour is now black as there are matching code stubs
Further enhancements with tabled data
The test is run once for each line in the table
1219-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Turning a feature into a test
Given [The test puts records in the database]When [The test uses a service client to call the service under test]Then [The test compares the result with an expected result]
1319-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Turning a feature into a test
Given [The test puts files in a directory]When [The test executes the dtsx (ssis) package]Then [The test compares the data in the database with an expected result]
1419-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Living Documentation
Documentation can be generated from the tests on check-in via the build server using Pickles. (http://www.picklesdoc.com)
Documentation can be generated in HTML (with or without search capabilities), JSON, Word, DITA or Excel formats.
Documentation can be generated via MS Build with a supplied task or with PowerShell
Generating documentation
Example Feature text appears here, so this can be more descriptiveTest result of last test run is appended to the documentation.
1519-Jan-14
© Copyright: City Boy Salary : Simon Powers : 2014
Resources
Other BDD tools• Cucumber - http://cukes.info/• Rspec - http://rspec.info/
Other documentation generation systems• Relish (https://relishapp.com)• SpecLog (http://www.speclog.org)
Other Resources• Tutorial on SpecFlow