Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test...

33
Unit Testing is like cooking! (you‘ll see!) Mario Rimann TYPO3 Developer Days 2008

Transcript of Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test...

Page 1: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Unit Testing is like cooking!(you‘ll see!)

Mario Rimann TYPO3 Developer Days 2008

Page 2: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework
Page 3: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

How?

Why?

Then?

Page 4: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

How?

Why?

Then?

Page 5: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Managing complexity

Page 6: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Managing complexity

Page 7: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Avoiding chain reactions

Page 8: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Regression

Page 9: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Saving time

??

?

?

Page 10: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Improving structure

Page 11: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Improving structure

Page 12: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

How?

Why?

Then?

Page 13: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Unit Testing is like cooking!

Classes to test

TestcasesEnvironmentfor Testing

Fixtures

Testing Framework

Page 14: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

PHPUnit≠

tx_phpunit... but somehow similar

LiveDemo

Page 15: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

A simple class:

class superMathematics {

static function add($a, $b) { return $a + $b; }

}

Page 16: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

A small Test Case:class superMathematics_testcase extends PHPUnit_testcase {

public function testAdd() { $this->assertEquals( 12, superMathematics::addition(5, 7) ); }}

Page 17: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

A more complex class:class tx_seminars_place extends tx_seminars_objectfromdb {

function getCity() { return $this->getRecordPropertyString('city'); }

function getCountryIsoCode() { return $this->getRecordPropertyString('country'); }}

Page 18: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Fixtures are like spices private $fixture;

public function setUp() { $uid = $this->testingFramework->createRecord( tx_seminars_sites, array( 'title' => 'TEST Place 1', 'city' => 'Tokyo', 'country' => 'JP' ) ); $this->fixture = new tx_seminars_place($uid); }

Page 19: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

A Test Case:class tx_seminars_place_testcase extends tx_phpunit_testcase { public function testGetCityReturnsCityName() { $this->assertEquals( 'Tokyo', $this->fixture->getCity() ); }

public function testGetCountryIsoCodeReturnsIsoCode() { $this->assertEquals( 'JP', $this->fixture->getCountryIsoCode() ); }}

Page 20: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Let‘s play!

Page 21: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Test different aspects

Functionality RegressionEdge cases

Page 22: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Kitchen Tools can help!

Page 23: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

How?

Why?

Then?

Page 24: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Risks of Unit Testing

Don‘t eat too much!

Don‘t cook bullshit!

Page 25: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Workflow

He‘s a cool developer!

That‘s the SVN Server!

Page 26: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Local testing

Coding

Unit Testing

drinking coffee

Subversion

Comitting only tested code!

Page 27: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Continous Integration

Coding

Unit Testing

drinking coffee

Subversion

Unit Testing

Page 28: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Continous Integration

Coding

drinking coffee

Subversion

Comitting un-tested code!

Unit Testing Unit Testing

Page 29: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

less than 2%

of all extensions in TER are unit tested

Page 30: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

feels good!

Page 31: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

How?

Why?

Then?

Page 32: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

page intentionally left blank for your questions

Page 33: Unit Testing is like cooking! - t3dd08.typo3.org fileUnit Testing is like cooking! Classes to test Testcases Environment for Testing Fixtures Testing Framework

Mario [email protected]

Screenteam GmbHFalkenstrasse 26CH-8008 Zürich

www.screenteam.com

Thanks for your attention...

... and happy cooking!