Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
The Future of Testing Magento 2 Modules with TDD and BDD
1. Page | 1
Where have we been and what
do we do?
The Future of
Testing Magento 2
2. Page | 2
About Me
James Cowie
● CTO @ Shero Commerce
● Magento Master
● BDD / TDD advocate
● @jcowie
● @sherocommerce
3. Page | 3Page | 3
➔ “The process of learning effective TDD is the process of
learning how to build more modular applications.”
The Goal
4. Page | 4Page | 4
➔ “The process of learning effective TDD is the process of
learning how to build more modular applications.”
The Goal
5. Page | 5
The Reasons to not test
➔ We don't have the budget!
➔ We don’t have the time!
➔ Testing slows us down!
➔ We don’t have the training!
➔ It gets in the way!
➔ The client won’t pay for it!
➔ The tests become out of date
➔ They run slow and hold us back!
➔ Ship first test later
6. Page | 6
Group the historical reasons
Time Knowledge Understanding
Testing slows us down! We don’t have the training! Ship first test later
We don’t have the time! The tests become out of date They run slow and hold us back!
We don't have the budget! Ship first test later
The client won’t pay for it!
8. Page | 8
Time to add features over time
without tests
● Faster to start with
● Slows down due to large code
● More time spent manual testing
● Higher chance of defects
9. Page | 9
Time to add features over time with
tests
● Does add time initially
● Get faster for feature development
● Less chance of defects
● Better use of time on exploratory
testing
● More maintainable
10. Page | 10
Time Conclusion
Testing slows us down
Over time testing speeds you up.
We don’t have time
Having tests will shorten delivery time making more
time.
The client won’t pay for it
Clients don’t need to know how you cook the steak.
Instead, they will pay for excellence and high quality.
35. Page | 35
The TDD dance
Write just enough
code to make the
test pass
36. Page | 36
The TDD dance
Refactor the code
to be complete
37. Page | 37
Think design / architecture
➔ Your only thinking about small units,
➔ Refactoring is safe,
➔ Your designing with interfaces,
➔ Stops gold plating.
38. Page | 38Page | 38
• This is a simple module but should highlight how simple
setup can be.
Lets see this in practice
39. Page | 39
The module / Demo
PayMate LTD provides the ability to part pay for goods and
split it over a number of months. They handle the payment
side of the process but they need the product details page to
show the split. The business rules are:
• Products under $50 can be split into 2 monthly payments
• Products under $200 can be split into 4 monthly payments
• Products over $500 can NOT be split
62. Page | 62
Refactoring Step
➔ Now that the tests pass Refactor!
➔ Remove the hard values for dynamic
➔ Keep running the tests
63. Page | 63
Integration testing
➔ Behat runs via Selenium
➔ The feature context is the powerhouse
➔ Its slower than Unit tests
➔ Can be optimized via Behat plugins