5 Levels of Automated Testing�of an Ecommerce Project - There Is No Silver Bullet
Petr Heinz
Lead Developer & Architect
The lock works well, but...
Testing
Goal: Assert that the application works as intended
You have to define �the expected behavior
Who does the testing?
Automated tests
Manual testing
petr-heinz@localhost:~/projects/shopsys-framework$ ./phing tests-unit
�Shopsys Framework > tests-unit:��PHPUnit 7.1.5 by Sebastian Bergmann and contributors.��................................................. 50 / 242 ( 21%)
................................................. 100 / 242 ( 41%)
................................................. 150 / 242 ( 62%)
................................................. 200 / 242 ( 83%)
......................................... 242 / 242 (100%)��Time: 134 ms, Memory: 12.00MB��OK (242 tests, 420 assertions)��BUILD FINISHED��Total time: 8.6212 seconds�
Different approaches�to automated testing
Unit tests
Test the smallest�amount of functionality�(i.e. a method)
Lightning fast execution
The tested code must be designed well to be testable
Great for testing isolated well-defined components
Functional tests
Test the interoperability�of classes
Can use services from�the DI container
May access a database or other storages
I recommend having�testing data fixtures
HTTP smoke tests
Checking just the HTTP status codes for all routes
“Is my app 200 OK?”
Almost maintenance free
Tests all new routes automatically
Prevents running into�a 500 error on�an unrelated page
Requires isolation of the database and other storages
shopsys / http-smoke-testing
a ready-to-use testing package for Symfony applications
Acceptance tests
Test end-to-end scenarios
Simulate real browser interaction
Excellent for business critical scenarios
Take a while to execute
We use Codeception and Selenium (via Docker)
Performance tests
Developing on a small dataset is dangerous
It can hide performance issues of new changes
Run the code on a larger dataset before deploying
Keep track of the changes�of response times
Try Gatling for load tests
You don’t want to run�them on your localhost
I ran out of memes…
...so no demo for you
| Unit | Functional | Smoke | Acceptance | Performance |
Subject of testing | results of method calls | interoperability of services | HTTP status codes of requests | end-to-end scenarios | response times with a large dataset |
Ideal application | isolated well-defined components | code that’s hard to unit test | protection from unhandled exceptions | business critical scenarios | preventing collapse on production data load |
Length of execution | very fast | fast | decent | slow | very slow |
Difficulty of maintenance | moderate | moderate | very easy | hard | depends |
Now you can be pretty sure about the behavior...
...but can we do more?
Coding standards
prevent problems with cooperation of devs
Static analysis - PHPStan
find errors without running the code
Architecture sniffs
applying CS to check your architecture
Automate it!
Automate it!
Automate it!
There is no silver bullet
Petr Heinz
Lead Developer & Architect
github.com/shopsys/shopsys
petr.heinz@shopsys.com
linkedin.com/in/petr-heinz
To learn more and check the slides go to�https://shopsys.com/u/tests
Wanted: Quality Assurance Developer�see https://jobs.shopsys.cz/ for details
Icons made by Freepik from www.flaticon.com.