7. SAME RULES
1.
7
You are not allowed to write any production code
unless it is to make a failing unit test pass.
8. SAME RULES
1.
2.
8
You are not allowed to write any production code
unless it is to make a failing unit test pass.
You are not allowed to write any more of a unit test
than is sufficient to fail; and compilation failures are
failures.
9. SAME RULES
1.
2.
You are not allowed to write any more of a unit test
than is sufficient to fail; and compilation failures are
failures.
3.
9
You are not allowed to write any production code
unless it is to make a failing unit test pass.
You are not allowed to write any more production code
than is sufficient to pass the one failing unit test.
12. CREATE THE TEST
private $calculator;
function setUp(){
$this->calculator = new Calculator();
}
function testSumTwoPositive(){
$expectedResult = 8;
$result = $this->calculator(6,2);
assertEquals($expectedResult,$result);
}
12
19. SPECIFICATION BY EXAMPLE
Scenario: Add two number
Given I fill number1 field with 2
And I fill number2 field with 6
When I press Add button
Then the result should be 8
19
25. GHERKIN
Scenario: Add two number
Given I fill number1 field with 2
And I fill number2 field with 6
When I press Add button
Then the result should be 8
25
31. Scenario: Add two numbers
Given I fill number1 field with value of 2
TRANSLATE
/**
* @Given /^I fill ([^’’]*) with (d+)$/
**/
public function iFieldFieldWith($number, $fieldName)
{
throw new PendingException();
}
31
40. Web Acceptance Test
GOUTTE
• Headless Browser
• No Javascript
• Really fast
40
SELENIUM
• Can test Javascript
• Really slow
• Use Firefox as emulator
41. Web Acceptance Test
GOUTTE
• Headless Browser
• No Javascript
• Really fast
41
SELENIUM
• Can test Javascript
• Really slow
• Use Firefox as emulator
Zombie.js
• Can test Javascript
• Medium
• Use Firefox as emulator
42. Web Acceptance Test
GOUTTE
• Headless Browser
• No Javascript
• Really fast
42
SELENIUM
• Can test Javascript
• Really slow
• Use Firefox as emulator
Zombie.js
• Can test Javascript
• Medium
• Use Firefox as emulator
SAHI
• Can test Javascript
• slow
• Emulate every Browser
43. Scenario: Add two numbers
Given I fill number1 field with 2
And I fill number2 field with 6
When I press Add button
Then the result should be 8
/**
* @When /^I press ‘’(/[^’’]*)’’ button$/
**/
public function iPressButton($buttonName)
{
$this->pressButton($buttonName);
}
43
46. Differs from documentation
because there is a fix for ZF2
multicheckbox selection
"require-dev " :{
.........
"behat/behat" : "2.4.*@stable",
"behat/mink": "1.5.0",
"behat/mink-extension":"*",
"behat/mink-browserkit-driver":"dev-master",
"behat/mink-goutte-driver":"*",
"phpspec/phpspec":" 2.0.*@dev"
}
46
58. BDD BASED ON BEHAVIOUR
DESCRIPTION
Robert C. Martin
59. PHPUnit focus on testing code
private $calculator;
function setUp(){
$this->calculator = new Calculator();
}
function testSumTwoPositive(){
$expectedResult = 8;
$result = $this->calculator(6,2);
assertEquals($expectedResult,$result);
}
59
60. PHPSpec focus on code behavior
function let(){
$this->shouldBeConstructed();
}
function it_sum_two_positive_number(){
$this->sum(2,6)->shouldReturn(8);
}
60
61. Subject under Specification
"It’s this unexisting object, on which you’re
calling unexisting methods and assuming future
outcomes. Most important thing? There could
be only one SUS in specification"
Kostantin Kudryashov
61
74. What to test with PHPSpec?
1.Model Logic
2.Factories
74
75. What to test with PHPSpec?
1.Model Logic
2.Factories
3.Validation
75
76. Behat bad practices
1. Verbose Stories
2. Using Mink to test REST calls
3. Testing every possible usages combination
4. Fixture loading within Context
76