Automated tests with phpunit is a puzzle, CI is the missing piece.
Automated unit test simply put is code testing another piece of code. Unit testing focuses on testing a small independent working part of the code which is generally a method/function. Unit tests need to be fast, offline, not dependent on database and test only one thing. Mocking other dependencies is a great way to unit test the class to be tested. To a beginner understand this is as difficult as solving a puzzle.
In this talk I will reveal how we wrote "unit" tests for a Laravel web application using PHPUnit and Mockery for mocking dependencies. I will also share why we chose PHPunit and Mockery and how testing helped up build better software.
With Continuous Integration, at every push, all the tests are run that covers the code changes. Continuous Integration helps us know where the project is at all times. What works, what doesn't and all the bugs you have in your system from a unit perspective with a fast feedback loop. If your change broke something existing you know it in minutes then you can fix your code and add more tests for the part you did.
Moreover continuous integration is a mentality to keep software quality high with having the build green for main branch in VCS all the time. CI goes like hand in glove with the issue flow and simplified gitflow that we follow. I will talk about how we integrated our automated tests with Shippable and the benefits of CI.
3. THE "WHAT"
- just code testing another code
-- means using an automation tool to execute your test suite
--- a process using software tools to execute pre-scripted
tests on an application before releasing into production
4. THE "WHY"
- manual testing of all work flows, all scenarios and
everything else is time and cost consuming
-- doesn't require human intervention
--- increases speed and accuracy of test execution
---- a lot of code coverage
5. TYPES OF TESTS - MAINLY
Unit Tests
Functional Tests
Integration Tests
6. UNIT TESTS
testing a small independent part of code
database independent
minimal or no file system dependence
isolated
deterministic
so it is fast
7. WHY UNIT TESTS ?
find problems early in the dev cycle
they facilitate change
they are good documentations
its fun..
12. WHY MOCKERY?
can mock static methods, unlike Prophecy
integrates easily with PHPUnit
13. HOW DO WE WRITE UNIT TESTS?
setup everything for testing
mock dependencies
trigger the method being tested
verify the results, that they are correct
17. unit tests..??how do we write GOOD
structure is important
consistent naming
mock everything you need
and write code that can be mocked
testable code
readable tests
18. test and verify only one specific part (single unit of work)
self sufficiency
24. THE MISSING PIECE
Continuous Integration
a development practice that requires developers to
integrate code several times a day
allowing teams to detect problems early
each push is verified by an automated build
the goal is to provide rapid feedback incase a defect is
introduced
25. CI is important because....
ensures on a continuous basis that you have a working
product
help detect bugs very early
27. WHY ?SHIPPABLE
it's free for private repo
supports docker
has unlimited builds
a lot of other cool features
28. WHAT DOES IT DO?
pulls changes from your repo and runs a build every time
you push anything
notify you of the success/failure of the build
you can even set it to notify you on hipchat