regression testing with symfony

23
Regression Testing with Symfony Tools and techniques for building your test suite

Upload: joachim-unger

Post on 13-Jan-2015

901 views

Category:

Technology


4 download

DESCRIPTION

For web applications you often need the ability to deploy new features continuously while making sure that all parts of your application still work correctly. Establishing an Continuous Integration process using an automated test suite can support you to meet those needs. This presentation tries to give an overview how this integration process can be established for Symfony2 applications and which types of tests apply. The presentation was held on the Symfony User Group Berlin on 10 Okt. 2012

TRANSCRIPT

Page 1: Regression Testing with Symfony

Regression Testing with SymfonyTools and techniques for building your test suite

Page 2: Regression Testing with Symfony

Introducing the speaker

Joachim Unger@joeywannabe

Symfony Explorer since 2.0Web Developer since 2010Former scientist at ABB Robotics

Software Developer @LittleBird GmbHBerlin

Page 3: Regression Testing with Symfony

Part 1: Exploring the techiques

Regression Testing Test granularities in web projects Basic design patterns Symfony test components Behaviour Driven Development Continuous Integration Lessons learned

Page 4: Regression Testing with Symfony

Regression Tests

Discover new software bugs (regression) Verify bugfixes on existing functionality Validate changes against other components Include rerunning previously run tests Run on each code change Ensure product quality Minimize risks

Page 5: Regression Testing with Symfony

Types of Regression Tests

Progressive Regression Tests Specification has changed Code has been changed

> Add new test cases

Correcting Regression Tests Specification has not changed Test code changes against existing test cases

Page 6: Regression Testing with Symfony

Regression Tests in web projects

Defined test strategy Test-Driven Programming

Tests for all code changes (e.g. bugfixes) Tests have to be up-to-date Continuous Refactoring

Automated Test Suite Run on each code change Smoke, Acceptance and Unit Tests Continuous Integration

Page 7: Regression Testing with Symfony

Software Quality

ORM/DBAL

Model

Controller

Utility

View

Browser

Structural Quality Design and structure of code Loose coupling of components Ensures extensibility of code

Functional Quality Error-free execution of application Strongly influences user acceptance

Page 8: Regression Testing with Symfony

Unit Tests

Verify functionality of single component Allow safe refactoring of code parts Must run successfully on each change Test is written with/before code

Assert that the result of foobar(“foo“) is “bar“.

Page 9: Regression Testing with Symfony

Acceptance Tests

Verify the functional requirements Ensure the overall application usability Test specification provided by stakeholder

Check that a click on button„Put on shopping cart“ puts the item

into the shopping cart

Page 10: Regression Testing with Symfony

Smoke Tests

Verify the overall application functionality Good to identify crucial bugs

Check that the url of a product pageis really showing a product page

Page 11: Regression Testing with Symfony

Separation Of Concerns

Separation of task in independent blocks Loose coupling between components Heavy use of dependency injection

MVC as an example Model: Exchange and storage of data View: Representaton of data Controller: Application Logic

Decoupling of unit tests

ORM/DBAL

Model

Controller

Utility

View

Browser

Page 12: Regression Testing with Symfony

Inversion Of Control

Removal of static assignments Framework only works with abstraction of components Object graph is instantiated dynamically

Separation of execution and implementation

Page 13: Regression Testing with Symfony

Unit Testing in PHP

phpunit: Status quo for testing in PHP Created by Sebastian Bergmann Originated as port of Junit Supports various features / extensions

Framework for embedding tests in application Execution as test suite for an project Mocking of injected objects Code & coverage analysis

Various functions for test assertions

Page 14: Regression Testing with Symfony

Test Components in Symfony

Unit Tests Enforce usage of dependency injection Testing of DBAL, model and relations Testing of components, utility classes Mocking of dependencies

Functional Tests Testing page reachability Testing of page content and links Easy utilization for smoke tests

http://symfony.com/doc/current/book/testing.html

Page 15: Regression Testing with Symfony

Behaviour Driven Development

Enhancement to Test-Driven Development Introduced by Dan North in 2006 Tests act as functional specification Missing link between developer and stakeholder

Justify functional requirements at beginning Software developed against functional specification Specified in a formal language (no experts needed) Clear focus on functionality

Page 16: Regression Testing with Symfony

BDD Test Specification

Scenario: Put item in shopping cartGiven the case, the customer wants to buy a movie

And his shopping cart is emptyAnd there are 2 movies in stock

When he puts the item in the shopping cartThen the item should show up in the shopping cart

And the shopping cart counter should show 1And 1 movie should be in stock

Page 17: Regression Testing with Symfony

Gherkin

Mink

BDD Testing Bundles

Behat

Formal language to describe test cases

Encapsulation of different browser drivers

Test Engine for executing Gherking test case

Integration of Mink into SymfonyMinkBundle

BehatBundle

Integration of Behat into Symfony

Page 18: Regression Testing with Symfony

Other Testing Bundles

DoctrineFixturesBundle Preparation of test data sets

LiipFunctionalTestBundle Simplifies preparation and execution Utilizes DoctrineFixturesBundle

PSSMockeryBundle (Symfony2MockerExtension) Mocking of services in DIC Demarcation of tests

Page 19: Regression Testing with Symfony

Continuous Integration

Continuous process to apply quality control Various CI Systems available

Bamboo, Jenkins, CruiseControl Successfull development process for CI

Direct feedback -> Short execution times Frequent checkins Commits to trunk Automated test chain Automated deploy -> Continuous delivery

Page 20: Regression Testing with Symfony

Automated Build Smoke Tests Unit Tests Syntax Tests Coding Standards Copy/Paste Detection Documentation

Continuous Integration

Periodical Build Smoke Tests Unit Tests Syntax Tests Coding Standards Copy/Paste Detection Documentation+ Acceptance Tests+ Other intensive tests

Page 21: Regression Testing with Symfony

Favoured Test Suite

Test-Driven Development Testing influences whole development process Loose coupling of components

Test chain according to granularities Smoke Tests: Routes, Firewalls (Reachability) Unit Tests: Modular components, Utility classes DBAL Tests: Entity, Relations and Repository BDD Tests: User Interface (Usability)

Continuous Integration System Triggers test chain on each commit Verifies state before final deploy

Page 22: Regression Testing with Symfony

Lessons learned

Commitment to TDD needed Testing influences software design Testing takes its time Quality can hardly be achieved later on Full test coverage almost unachievable Regression tests need automated test suite Testing only way to ensure software quality

Page 23: Regression Testing with Symfony

Questions

Questions regarding the practicalusage probably covered in part 2