unit testing for project managers
TRANSCRIPT
2© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Presenter
Cal EvansTechnical Manager, Training and
CertificationRogue Wave [email protected]
3© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Agenda
1. Exactly what is Unit Testing?2. Why should my teams bother writing them?3. Ok, I get it, but now when should my teams
start writing unit test?4. You’ve left out the most important part, how
do my teams go about writing Unit Tests?5. Q&A
4© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Poll #1How many developers do you have at your company?
6© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Unit testing is a software developmentUnit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation.
What
7© 2017 Rogue Wave Software, Inc. All Rights Reserved.
What
public function testCreateMessage()
{
$account = new Account($this->db,1);
$message = new Message($this->db,null,$account);
$message->text ="This is a test message.";
$message->save();
$this->assertEquals($message->id,1);
$this->assertEquals($message->text ,"This is a test message.");
$this->assertEquals($message->front_end_account_link_id,1);
return;
}
9© 2017 Rogue Wave Software, Inc. All Rights Reserved.
What
The question you are faced with is not WHY, the question you are faced with is:
“What will my projects look like when I adopt unit testing
as a best practice?”
10© 2017 Rogue Wave Software, Inc. All Rights Reserved.
What
Development
Working unit tests
Organized chaos
The beginnings of understandin
gChaos
11© 2017 Rogue Wave Software, Inc. All Rights Reserved.
What
The Payoff
DevelopmentChange request
Change complete
13© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Poll #2Do you currently do unit testing at your company?
15© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Why
Automated tests help you get things right the first time,
costing less.
16© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Why
There’s never time to do it right, there’s
always time to do it over.
18© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Why public function respond(ResponseInterface $response) { if (!headers_sent()) { header(sprintf( 'HTTP/%s %s %s', $response->getProtocolVersion(), $response->getStatusCode(), $response->getReasonPhrase() )); } if (!$this->isEmptyResponse($response)) { $body = $response->getBody(); if ($body->isSeekable()) { $body->rewind(); } $settings = $this->container->get('settings'); $chunkSize = $settings['responseChunkSize']; $contentLength = $response->getHeaderLine('Content-Length'); if (!$contentLength) { $contentLength = $body->getSize(); } if (isset($contentLength)) { $amountToRead = $contentLength; while ($amountToRead > 0 && !$body->eof()) { $data = $body->read(min($chunkSize, $amountToRead)); echo $data; $amountToRead -= strlen($data); if (connection_status() != CONNECTION_NORMAL) { break; } } } else { while (!$body->eof()) { echo $body->read($chunkSize); if (connection_status() != CONNECTION_NORMAL) { break; } } } } }
=
19© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Why
If your current project management style does not allow for time to create unit
tests, change your style.
20© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Why
7 reasons why writing unit tests is important to managers
(From Tim King)
Unit tests prove that your code actually worksYou can improve the design without breaking it
They demonstrate concrete progress
Test-first forces you to plan before you code
Test-first reduces the cost of bugs
Unit tests make better designs
It’s faster than writing code without tests
23© 2017 Rogue Wave Software, Inc. All Rights Reserved.
When
“The best time to plant a tree was 20 years ago. The second best time is now.” – Chinese proverb
25© 2017 Rogue Wave Software, Inc. All Rights Reserved.
How
• Train your developers• Pick a project to begin
with• Think it through• Write your tests• Write your code
It all starts with
training.
26© 2017 Rogue Wave Software, Inc. All Rights Reserved.
How
PHP Unit Testing JumpStart• What is test driven development?• Modularizing code• Assertions• Doubles and dummies• Mocking and stubs• Data providers• Code Katas
27© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Start testing today!
zend.com/unittest
for more information
29© 2017 Rogue Wave Software, Inc. All Rights Reserved.
Follow up
Twelve Benefits of Writing Unit Tests First (Tim King)– sd.jtimothyking.com/2006/07/11/twelve-benefits-of-writing-unit-tests-
first/ I Pity The Fool Who Doesn’t Write Unit Tests (Coding Horror)
– blog.codinghorror.com/i-pity-the-fool-who-doesnt-write-unit-tests/Top 12 Reasons to Write Unit Tests (O’Reilly on Java)
– onjava.com/pub/a/onjava/2003/04/02/javaxpckbk.html10 Best Automated Testing Frameworks for PHP (HONGKIAT)
– hongkiat.com/blog/automated-php-test/