Successfully reported this slideshow.
Upcoming SlideShare
×

of

0

Share

# Introduction to testing

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

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"

Total views

352

On Slideshare

0

From embeds

0

Number of embeds

11

4

Shares

0