Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Testing
Trust your code
About me
MANEL SELLÉS
Software engineer
at Ulabox
FIBer
@manelselles
Testing
Do the right thing
VS
do the thing right
Testing
What is testing?
Testing
Testing
Why is it usefull?
Testing
● Say it once, check every time automatically.
○ “Don’t do repetitive checks”
● Increase reliability and quality o...
Testing
Testing
VS
Debugging
Testing
Testing
Example
Testing
Fibonacci
● 0 : 0
● 1 : 1
● 2 : 1
● 3 : 2
● 4 : 3
● 5 : 5
● 30 : 832040
● 40 : 102334155
● 102 : 927372692193078999
Testing
/**
* Fibonacci using an iterative approach
*/
public function fibonacci($n)
{
$a = 0;
$b = 1;
for ($i = 0; $i < $...
Testing
function testFibonacci()
{
echo ($this->fibonacci(0) === 0) === TRUE;
echo ($this->fibonacci(1) === 1) === TRUE;
e...
Testing
class FibonacciTest extends PHPUnit_Framework_TestCase
{
function testFibonacci()
{
$this->assertEquals($this->fib...
Testing
/**
* Fibonacci using recursion
*/
public function fibonacci($n)
{
if ($n == 0) {
return 0;
}
if ($n == 1) {
retur...
Testing
Assertions
● assertEquals
● assertEmpty
● assertSame
● assertInstanceOf
● assertArrayHasKey
● assertArrayHasSubset...
Testing
Coverage
Testing
Testing
Test doubles
(to substitute dependencies)
Testing
Without behaviour
● Dummy -> no content
● Stub -> to guide the test
With behaviour
● Fake -> to simulate
● Spy -> ...
Testing
Testable Code
Testing
● Global can not be substituted
○ Avoid static and singleton
● It’s easier to fake collaborators
○ Composition ove...
Testing
Test Driven
Development
(TDD)
Testing
Testing
QA/tester/developer
Thanks
May the test be with you
Upcoming SlideShare
Loading in …5
×

0

Share

Download to read offline

Introduction to testing

Download to read offline

Talk given to university students during the "Seminari UPC 2017"

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Introduction to testing

  1. 1. Testing Trust your code
  2. 2. About me MANEL SELLÉS Software engineer at Ulabox FIBer @manelselles
  3. 3. Testing Do the right thing VS do the thing right
  4. 4. Testing What is testing?
  5. 5. Testing
  6. 6. Testing Why is it usefull?
  7. 7. Testing ● Say it once, check every time automatically. ○ “Don’t do repetitive checks” ● Increase reliability and quality of software. ○ “I didn’t think of that!” ● Discover regressions in software. ○ “Why did it break?” ● Improve confidence in our code. ○ “I think this will work.”
  8. 8. Testing Testing VS Debugging
  9. 9. Testing
  10. 10. Testing Example
  11. 11. Testing Fibonacci ● 0 : 0 ● 1 : 1 ● 2 : 1 ● 3 : 2 ● 4 : 3 ● 5 : 5 ● 30 : 832040 ● 40 : 102334155 ● 102 : 927372692193078999
  12. 12. Testing /** * Fibonacci using an iterative approach */ public function fibonacci($n) { $a = 0; $b = 1; for ($i = 0; $i < $n; $i++) { $c = $a; $a = $b; $b += $c; } return $a; }
  13. 13. Testing function testFibonacci() { echo ($this->fibonacci(0) === 0) === TRUE; echo ($this->fibonacci(1) === 1) === TRUE; echo ($this->fibonacci(2) === 1) === TRUE; echo ($this->fibonacci(3) === 2) === TRUE; echo ($this->fibonacci(4) === 3) === TRUE; echo ($this->fibonacci(5) === 5) === TRUE; echo ($this->fibonacci(30) === 832040) === TRUE; echo ($this->fibonacci(40) === 102334155) === TRUE; echo ($this->fibonacci(102) === 927372692193078999) === TRUE; }
  14. 14. Testing class FibonacciTest extends PHPUnit_Framework_TestCase { function testFibonacci() { $this->assertEquals($this->fibonacci(0), 0); $this->assertEquals($this->fibonacci(1), 1); $this->assertEquals($this->fibonacci(2), 1); $this->assertEquals($this->fibonacci(3), 2); $this->assertEquals($this->fibonacci(4), 3); $this->assertEquals($this->fibonacci(5), 5); $this->assertEquals($this->fibonacci(30), 832040); $this->assertEquals($this->fibonacci(40), 102334155); $this->assertEquals($this->fibonacci(102), 927372692193078999); } }
  15. 15. Testing /** * Fibonacci using recursion */ public function fibonacci($n) { if ($n == 0) { return 0; } if ($n == 1) { return 1; } return $this->fibonacci($n - 1) + $this->fibonacci($n - 2); }
  16. 16. Testing Assertions ● assertEquals ● assertEmpty ● assertSame ● assertInstanceOf ● assertArrayHasKey ● assertArrayHasSubset ● assertCount ● assertNull
  17. 17. Testing Coverage
  18. 18. Testing
  19. 19. Testing Test doubles (to substitute dependencies)
  20. 20. Testing Without behaviour ● Dummy -> no content ● Stub -> to guide the test With behaviour ● Fake -> to simulate ● Spy -> a call has been made ● Mock -> ensure expectation
  21. 21. Testing Testable Code
  22. 22. Testing ● Global can not be substituted ○ Avoid static and singleton ● It’s easier to fake collaborators ○ Composition over inheritance ○ Isolate dependencies ○ Inject dependencies ● It’s easier to test small and one-responsibility classes ○ Single responsibility principle
  23. 23. Testing Test Driven Development (TDD)
  24. 24. Testing
  25. 25. Testing QA/tester/developer
  26. 26. Thanks May the test be with you

Talk given to university students during the "Seminari UPC 2017"

Views

Total views

352

On Slideshare

0

From embeds

0

Number of embeds

11

Actions

Downloads

4

Shares

0

Comments

0

Likes

0

×