29
Testing Magento Florinel Chis @ florinelchis London Magento User Group – December Meetup

Magento Testing - London Magento User Group, December Meetup

Embed Size (px)

DESCRIPTION

My presentation about Magento Testing, 4th of December 2013, London Magento User Group, December Meetup. You can test any aspect of Magento. Having a continuous integration process in place and test coverage will give your development team confidence to release new functionality even on a Friday afternoon. Florinel is currently co-founder and Chief Service Officer at Elastera (http://www.elastera.com), a cloud-based Platform as a Service for Magento e-commerce sites.

Citation preview

Page 1: Magento Testing - London Magento User Group, December Meetup

Testing MagentoFlorinel Chis

@florinelchis

London Magento User Group – December Meetup

Page 2: Magento Testing - London Magento User Group, December Meetup

whoami

Fully managed cloud PaaS for Magento

Co-Founder and Chief Service Officer

- Development Lead at Warner Music- 11 years in e-commerce- Magento since 2008

Page 3: Magento Testing - London Magento User Group, December Meetup

Magento Testing

• Unit Testing

– Tools

– EcomDev_PHPUnit

• Functional Testing (CasperJS)

• Performance Testing

– Web page performance testing

– XHProf, Aoe_Profiler

• Resources

Page 4: Magento Testing - London Magento User Group, December Meetup

Unit Testing

• Available tools:

– plain phpunit

–MTAF

– EcomDev_PHPUnit

– TechDivision_MagentoUnitTesting

–Mage-Test

Page 5: Magento Testing - London Magento User Group, December Meetup

Plain phpunit

• Test API calls

• Test libraries

• Other basic tests

• Any other aspect of Magento that is

not dependent on things like session

• Requires lots of effort in “setUp()”

Page 6: Magento Testing - London Magento User Group, December Meetup

EcomDev_PHPUnit

• Integrated with Magento

• Supports Fixtures

• You can test pretty much any aspect

of Magento (Controllers, Models,

Layout, Config, etc)

Page 7: Magento Testing - London Magento User Group, December Meetup

Database settings

• app/etc/local.xml.phpunit

<phpunit>

<allow_same_db>?</allow_same_db>

</phpunit>

• 0

– Requires a separate db for the tests

• 1

– You can use the same db that Magento uses (local.xml)

Note: Fixtures will delete all existing records (@see ::apply() function in

Fixture/Processor/*)

Page 8: Magento Testing - London Magento User Group, December Meetup

Module Structure

#Namespace/Module/etc/config.xml <phpunit> <suite> <modules> <Namespace_Module /> </modules> </suite> </phpunit>

#Test files:Namespace/Module/Test/PathTo/Class.phpNamespace/Module/Test/fixtures/*.yamlNamespace/Module/Test/expectations/*.yamlNamespace/Module/Test/providers/*.yaml

Page 9: Magento Testing - London Magento User Group, December Meetup

Testing Emails

• Extend

Mage_Core_Model_Email_Template

• Mailcatcher.me (+API)

Page 10: Magento Testing - London Magento User Group, December Meetup

Mage_Core_Model_Email_Template

Mage::getConfig()->setNode(

'global/models/core/rewrite/email_template',

'Namespace_Test_Model_Email_Template'

);

// This is a hack to get the runtime config changes to take

effect

Mage::getModel('core/email_template');

$mailTemplate = Mage::getModel('core/email_template');

//… do your stuff

Note: https://github.com/MageTest/Mage-Test is the inspiration

for this approach

Page 11: Magento Testing - London Magento User Group, December Meetup

Mailcatcher configuration

$ gem install mailcatcher

$ mailcatcher

php.ini:

sendmail_path = /usr/bin/env catchmail -f [email protected]

#REST API:

/messages

/messages/1.plain

/messages/1.json

Page 12: Magento Testing - London Magento User Group, December Meetup

Mailcatcher

Page 13: Magento Testing - London Magento User Group, December Meetup

CI Integration

• jenkins-php.org

• Book: Integrating PHP Projects with

Jenkins by Sebastian Bergmann

Page 14: Magento Testing - London Magento User Group, December Meetup

Examples

• Unit Test Demo

Page 15: Magento Testing - London Magento User Group, December Meetup

Functional Testing with CasperJS

“CasperJS is an open source navigation scripting & testing

utility”

• Writtern for PhantomJS or SlimerJS

• Good for “writing functional test suites,

saving results as JUnit XML”

• Other cool features: take screenshots, test

remote DOM, scrape web documents

Page 16: Magento Testing - London Magento User Group, December Meetup

‘No more CAPTCHAs, end robot

discrimination’

Page 17: Magento Testing - London Magento User Group, December Meetup

Why CasperJS

• Friendly

• Javascript

• Quick

• Simple

Page 18: Magento Testing - London Magento User Group, December Meetup

Performance testing

• Web Page

– webpagetest.org

– PageSpeed

– YSlow

– other tools

• Magento

Page 19: Magento Testing - London Magento User Group, December Meetup

• CI Integration

– webpagetest.org API

– PhantomJS + YSlow

Page 20: Magento Testing - London Magento User Group, December Meetup

PhantomJS + YSlowphantomjs yslow.js http://yslow.org

phantomjs yslow.js -i grade -f xml www.yahoo.com www.cnn.com

www.nytimes.com

phantomjs yslow.js --info all --format plain --ua "MSIE 9.0"

http://yslow.org

phantomjs yslow.js -i basic --rulseset yslow1 -d http://yslow.org

phantomjs yslow.js -i grade -b

http://www.showslow.com/beacon/yslow/ -v yslow.org

phantomjs --load-plugins=yes yslow.js -vp 800x600

http://www.yahoo.com

phantomjs yslow.js -i grade -f tap -t 85 http://yslow.org

Page 21: Magento Testing - London Magento User Group, December Meetup

CSS Testing

• CSSLint

• PhantomCSS

Page 22: Magento Testing - London Magento User Group, December Meetup

CSSLint

• csslint --warnings=box-model,ids

filename.css

– [--format=junit-xml | checkstyle-xml]

Page 23: Magento Testing - London Magento User Group, December Meetup

PhantomCSS

• https://github.com/Huddle/

PhantomCSS

Page 24: Magento Testing - London Magento User Group, December Meetup

PhantomCSS Tips

• Avoid dynamic data (homepage

menu, banners)

• Use version control for the base

pictures (and make sure you update

them when they should change)

• Use the same OS/browser/viewport

Page 25: Magento Testing - London Magento User Group, December Meetup

Magento Performance - XHProf

“XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based user interface.”

Magento modules: Demac_Xhprof and Liip_Xhprof

Page 26: Magento Testing - London Magento User Group, December Meetup

Aoe_Profilerhttps://github.com/fbrnc/Aoe_Profiler

Page 28: Magento Testing - London Magento User Group, December Meetup

Questions?