Alley Hacks:Contribute to Fieldmanager – TDD and Unit Testing – Let's get to work!



Alley Hacks:Contribute to Fieldmanager – TDD and Unit Testing – Let's get to work!

0 0


fm-contrib

FM Contribution Presentation

On Github alleyinteractive / fm-contrib

Alley Hacks:Contribute to Fieldmanager

Settle in and apm install wordpress-develop

Pre-requisites

broadway/www/wordpress-develop/ must exist

apm install wordpress-develop
					

TDD and Unit Testing

TDD: Write your (failing) tests first, then make them pass.

TDD and Unit Testing

It all starts with the tests!Let's go to our Fieldmanager directory and run them:

cd ~/broadway/plugins/wordpress-fieldmanager/
phpunit
						

TDD and Unit Testing

Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 4.2.6 by Sebastian Bergmann.

Configuration read from /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/phpunit.xml

...............................................................  63 / 158 ( 39%)
............................................................... 126 / 158 ( 79%)
................................

Time: 13.83 seconds, Memory: 33.00Mb

OK (158 tests, 1690 assertions)
						

TDD and Unit Testing

phpunit --group=quickedit

F.....

Time: 2.11 seconds, Memory: 26.75Mb

There was 1 failure:

1) Test_Fieldmanager_Context_Quickedit::test_context_render
Failed asserting that '' contains "fm-quickedit".

/var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/tests/php/test-fieldmanager-context-quickedit.php:128

FAILURES!
Tests: 6, Assertions: 40, Failures: 1.
						

TDD and Unit Testing

PHPUnit is a unit testing framework. You use it to test small, individual units of functionality

TDD and Unit Testing

Don't be intimidated! Writing unit tests is simple and fun

TDD and Unit Testing

For FM, there's the PHPUnit framework, but there's also an extension provided by WordPress Core

  • PHPUnit: there's a lot to it, but the mostimportant bits are its assertions
  • WP: the most important bits are its factories(read more: here and here).

TDD and Unit Testing

Code Coverage: a helpful report card

xdebug_on
phpunit --coverage-html ./report
						

TDD and Unit Testing

What does a test look like?

function test_truthiness() {
	$this->assertTrue( true );
}
						

TDD and Unit Testing

What about JS?

Someone, please, set that up

Let's get to work!

Five options

Improve documentation Fix bugs (Frontend/Backend) Add new features (Frontend/Backend) Code cleanup Finish and merge and existing PR

Improve Documentation

Fix Bugs - Frontend

Fix Bugs - Backend

Add New Features - Frontend

Add New Features - Backend

Code Cleanup