1 19-jan-14 © copyright: city boy salary : simon powers : 2014 brown bag – behaviour driven...

15
1 19-Jan-14 ight: City Boy Salary : Simon Powers : 2014 n Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development with

Upload: carina-loos

Post on 28-Mar-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

119-Jan-14

© Copyright: City Boy Salary : Simon Powers : 2014

Brown Bag – Behaviour Driven Development with Specflow

Brown Bag – Behaviour Driven Development with

Page 2: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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.

Page 3: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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.

Page 4: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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

Page 5: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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.

Page 6: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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

Page 7: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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

Page 8: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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

Page 9: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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

Page 10: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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

Page 11: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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

Page 12: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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]

Page 13: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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]

Page 14: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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.

Page 15: 1 19-Jan-14 © Copyright: City Boy Salary : Simon Powers : 2014 Brown Bag – Behaviour Driven Development with Specflow Brown Bag – Behaviour Driven Development

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