This document discusses unit testing in WordPress. It defines unit testing as automated tests that check single assumptions of code. The benefits of unit testing are instant feedback, low chance of errors, and embedding knowledge in code. PHPUnit is introduced as the main tool for unit testing in WordPress. Key aspects of unit testing covered include the Arrange, Act, Assert structure of tests; writing tests before or after code; and common PHPUnit assertions. The document provides an example unit test and contact info for the author.
2. BARRY KOOIJ
Senior Web Developer @ Yoast
Plugin developer
What The File
Sub Posts
Contributor EDD
EDD extensies
Moderator WPNL forum
Twitter: @cageNL
13. TWO WAYS OF UNIT TESTING
Write your tests, then write code to make your tests pass
Write your code, then write tests that pass
14. PHPUNIT
A command line tool that runs unit tests & reports their
results.
Created by Sebastian Bergmann
Integrated in most IDE (Eclipse, Netbeans, PHPStorm)
Auto installed in Vagrant w/ Varying Vagrant Vagrants
15. UNIT TESTS REQUIREMENTS
Each test should be able to run on its own (isolated)
Easy to read
Quick to execute
Self explaining function names
Test classes should inherit from WP_UnitTestCase (which
inherits from PHPUnit_Framework_TestCase)
Test functions should start w/ test (test_my_test_name)
16. ARRANGE ACT ASSERT
Setup the context, all variables etc.
!
Call the method, do the action, query the database, etc.
!
Check if the result matches the expectations.
20. ASSERTION
A way of explicitly checking the assumptions that your
code makes.
!
assertEqual()
assertTrue()
assertNotNull()
assertContains()
assertGreaterThan()
!
http://phpunit.de/manual/3.8/en/writing-tests-forphpunit.html#writing-tests-for-phpunit.assertions