There are many types of automatic tests, testing tools, libraries and approaches.
Automatic tests can save you a lot of stress but can also became a kind of a nightmare.
This presentation is an overview of what's available and how to use and not to use them to make them really useful.
Examples taken from PHP world. You might be surprised how many tools is available.
2. Preface
There are many types of automatic tests, testing tools, libraries and approaches.
Automatic tests can save you a lot of stress but can also became a kind of a nightmare.
This presentation is an overview of what's available and how to use and not to use
them to make them really useful.
Examples taken from PHP world. You might be surprised how many tools is available.
3. Agenda
What is a test?
The tools
How to start and progress
Challenges
4. About me
Damian Sromek
PHP Developer since ~2010
BlaBlaCar.com; Weemto.com; Xstream.net; X-Formation.com
Linked In Profile
5. Test? Why?
To make the user happy.
To make your boss happy.
To make your company happy.
To make you happy.
6. Test
Make sure software works - quality assurance
Make sure software does what it’s supposed to do
Make sure software stays working
7. Test - Types
Large: Acceptance, End to end
User can buy a book using web browser
Medium: Integration, Functional
Internal API call to shop service works fine when external payment system is mocked.
Small: Unit
Class computes the price correctly.
8. Test
Manual
Performed by human - usually a student clicking all day long.
Automated
Performed by computer - usually PHPUnit clicking all day long.
Manual + Automated
Human tester clicking to prepare a new testing scenario that will be automated next.
10. Automated Tests
Computer is much faster at testing than human
Computer tool checks the software. Eg. clicks around
Deliver fast and with less worries - especially when working with many people
Protect against regression
Allows easier testing of edge and hard to reproduce cases
PHP tools
http://www.phptherightway.com/#testing
11. Automated Tests = Happy
Avoiding for slow, boring “monkey” testing
Avoiding testing again and again, … and again
You can debug easier
You know when you break things
You know when other people break things - they fix it
12. TDD, BDD, DDD
TDD - Test Driven Development
Know your software/class requirements before implementing it.
Behavior Driven Development
Know your business by writing down user’s behaviour
DDD - Domain Driven Design
Know your business first by modeling the domain and events
Development <-> Design
14. Automated Integration Tests
Test if multiple classes work together
Test if “classes” work properly with external WebService, Database
PHPUnit
Codeception
Behat (!) - contexts
18. How? When?
Know your project, team, goals, definition of done
WordPress website vs banking system
Define risks and make a simple test plan
Text has wrong size vs user unable to pay
Start with the simplest solution and evolve
19. Other (Un)expected Benefits
Better understanding of “the purpose” of the software
Safer refactoring
Better code design and quality
Documentation of features and a design
Faster development of a better software!
20. Is it easy?
“It depends”
Need to learn a new things - tools, change the way of thinking.
Was learning OOP easy?
Writing Integration and Unit tests can be really hard if you have poor code design
Writing a good test requires you to “become a tester”
21. Learn
Books
Growing Object-Oriented Software, Guided by Tests
Testowanie i jakość oprogramowania. Metody, narzędzia, techniki
YouTube, conferences
Open source projects
Symfony: PHPUnit
Sylius: Behat, PHPSpec
Web
Wikipedia
Testing on toilet
Uncle Bob
22. Excuses
I create a code that works
It works on my computer
I don’t know how to write tests
I don’t like writing tests
I have no time for writing tests
It’s not possible to test this
It’s quite hard to measure the benefits
23. Good Start - Bugs!
1. Get a bug report
2. Reproduce it by writing an automatic test
3. Fix it!
24. Good Start - High Level
If you’re responsible for the whole project
Basic Acceptance Tests
then basic Integration Tests
then basic Unit Tests
25. But What Tool(s)?
A tool you or other devs are familiar with
A tool that’s quite popular - big comunity
A tool that fits your needs
As few tools you need
A tool with good support in IDE, automation platforms etc.
Usually PHPUnit would be a good start
Vagrant, Docker
“Great software development is not about the tools you use but about how you use
26. On the way
Use Continuous Testing (eg. Jenkins)
Keep tests close to the source code
Keep the tests quality at the best possible level
Have as much tests as you need - not more
Keep it simple
How much tests?
Acceptance < Integration < Unit
Keep test execution time as low as possible
27. Master Level
Test Driven Development / Design
Desing / Test -> Implement -> Refactor
IDE for running tests with debugger
Every feature and bug fix with an automatic test
You shall not merge on failing tests
Test groups, desciptive names and fail messages
The same test suites for many environments
29. Good Automated Test
Shows what the software does
Hides how the software works
“I should not be able to tell what’s the implementation by reading the test” - Me
Protects from bugs ;)
Should let you replace feature implementation
Should speed up your daily work
Fails with descriptive and easy to understand message
Is independent and repeatable
30. Challenges
Having a lot of poor quality code
Execution takes too long
Try to move to Unit tests. Acceptance tests for the simplest scenarios;
Database in RAMDisk
Mock-hell
Try not to overuse mocks. Some classes are made to integrate things.
Too many tests
Check if the tests are really usefull. If not then remove some.
Do they really check something useful?
Randomly failing tests
Try not to make tests depend on real time/date. Eg. mock the clock.
31. Quality Metrics
Number of tests and assertions
Execution time
Code coverage
Number of bugs found during development
Number of bugs protected against - regression
Speed of developing new, WORKING features
Certainty of releasing new version of software
32. Is it worth it?
YES!
Automation for the win!
Automated tests for the win!
33. Testing Legacy Projects
- Test only at a high level if you know your internals needs to be replaced/improved
34. Testing Large and Complex Systems
Online Video Platform
Web, Backend, Queue, Distributed
FTP upload; Wait for asynchronous actions; Check GUI;
Set Top Box app
Selenium; WebSockets
Behat scenarios in Jenkins task config