put an end to regression with codeception testing
TRANSCRIPT
Put an end to regression with Codeception Testing
Joe Ferguson
Who Am I?Joe Ferguson
PHP Developer
Engineer @ Aol.
Twitter: @JoePFerguson
Organizer of @MemphisPHP
OSMI Board Member
@NomadPHP Lightning Talks
Passionate about Community
Testing Resources
http://grumpy-learning.com
Assumptions
You know you need to write tests
You have written a test or two before
You might have even like writing tests
“There are no solutions, only trade offs”
- Joe Ferguson
- Paul M. Jones
- Thomas Sowell
How is your test coverage?
Code Metrics
Code Climate - Grades your code quality
Coveralls - Shows what code is not covered by your test suite
PHPUnit Code Coverage Analysis
When your app crashes how hard does it crash?
“Can’t see the forest for the trees”
“Can’t see the forest for the trees”X XApp on Fire unit tests
^ ^
2 unit tests 0 integration tests
https://twitter.com/thepracticaldev/status/687672086152753152
2 unit tests 0 integration tests
2 unit tests 0 integration tests
https://twitter.com/ThePracticalDev/status/852508104914874369
Unit Tests ARE Important
Testing Trinity
Unit Tests - This method works
Functional Tests - This feature works
Acceptance Tests - This product works
Testing Trinity
Unit Tests - I know what broke
Functional Tests - Something Broke
Acceptance Tests - This product broke
Regression Testing
Regression Testing is Easy**
Bug Report Scenario
User reports that feature “Return Foo” always returns “Bar”
Create a test to ensure that feature “Return Foo” returns “Foo”
See test fails to confirm report or verify there is no bug
Correct your application logic and make your user happy
You should not run into this bug again*
* If you do, you know because you have a test!
Install Codeception
Set Up Codeception
Codeception Files
Unit Test Suite
HomeController Foo Function
New Unit Test
./vendor/bin/codecept g:phpunit unit "App\Http\Controllers\HomeController"
HomeControllerTest.php
Write our test for foo()
Run our test
Run only unit tests
Later that week…
We caught the bug!
Customer Confidence++
I can do that with PHPUnit!
Functional Testing
This feature works
Functional Tests TL;DR
https://twitter.com/RebeccaSlatkin/status/852627030092939274
Baked in Functional Testing
Functional Test Suite
New Functional Test
./vendor/bin/codecept g:cept functional HomeController
Functional Test
HomeController.php
Test to verify we get redirected
Run our Functional Tests
Expand Our Test
Run our Functional Tests
Test Failure
Test Failure Output
What if something breaks?
Of course our test fails…
Browser Output on Failure
Acceptance Tests
This product works
PhantomJS
Acceptance Test Suite
New Acceptance Test
./vendor/bin/codecept g:cept acceptance RegisterCept
RegisterCept.php
Run Our Test
Run ALL the tests
There is not much difference between functional and acceptance tests
Reuse Test Logic
Refactor RegisterCept.php
UserCanLoginCept.php
Run our tests
There is a problem with our configuration of Codeception
Create a Clean DB Snapshot
codeception.yml
acceptance.suite.yml
Codecept Build
DB is cleaned up after
Testing for Specific Content
Testing Navigation Clicks
Legacy Applications
Recap
Unit tests are important!
Use functional and acceptance suites to test operation of you applications
Turn every bug report into a regression test so you’ll catch issues faster
Too many regression tests? Could indicate workflow or UI/UX issue in your application
Questions?
Feedback!
https://joind.in/talk/b7324
Joe FergusonTwitter: @JoePFergusonEmail: [email protected]: joepferguson
Contact Info: