Presented by Guyllaume Cardinal for Cogeco Connexion
TDD vs BDD
Benefits of TDD
Coding principles: SOLID, GRASP Single Responsability principle
Code smells
Tests a single unit (class)
Focus on behavior
Mocks are used to isolate what is being tested
Test a feature
Multiple classes interact together
Use abstractions to remove binding to web services and databases
How developers imagine users:
Acceptance tests are basically a user (or a QA person) visiting and interacting with your website and expecting certain things
The Given-When-Then formula is a template intended to guide the writing of acceptance tests for a User Story:
Feature: Serve coffee
In order to earn money
Customers should be able to
buy coffee at all times
Scenario: Buy last coffee
Given there are "1" coffees left in the machine
And I have deposited "1" dollar
When I press the "coffee" button
Then I should be served a coffee
Scenario: I download a file
Given I am in a directory "/foo"
<?php
class FeatureContext extends BehatContext
{
/**
* @Given /^I am in a directory "([^"]*)"$/
*/
public function iAmInADirectory($dir)
{
if (!file_exists($dir)) {
mkdir($dir);
}
chdir($dir);
}
}
Writen in plain english (most of the time)
Black box testing
In a real browser
Very, very, high level
Tests the "happy path"
Primarily a preference
Allows stakeholders and PO to understand what's tested
Personally: Behat is a good tool
Behat report
Acceptance tests are sloooow
Acceptance tests are very fragile
Acceptance tests can't really test edge cases
Acceptance tests should not care about the underlying system
Website loads
CSS and JS loads
Navigation
Critical Path (vital flows of your app)
Anything that can't be covered by Unit or Integration tests
Unit:
Integration:
Acceptance:
Test each class individually
Test whole features and class interaction
Test that the app behaves like the user expects it to
And it's all automatic!
cogeco.ca