advanced live testing em tempo real
DESCRIPTION
Nelson Senna e Augusto Pascutti mostram em tempo real Advanced Live Testing no InterCon PHP 2014. O InterCon aconteceu no último dia 19 de Julho no Intercontinental em São Paulo - http://interconphp.imasters.com.br/TRANSCRIPT
![Page 1: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/1.jpg)
Advanced Live TestingAugusto Pascutti / Nelson Senna
![Page 2: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/2.jpg)
Advanced Live TestingAugusto Pascutti / Nelson Senna
![Page 3: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/3.jpg)
Nossa experiência com TDDAugusto Pascutti / Nelson Senna
![Page 4: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/4.jpg)
Os pilotos
![Page 5: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/5.jpg)
Augusto Pascutti
Twitter: @augustohp Github: augustohp Slides: http://bit.ly/augustohp Blog: http://augustopascutti.com
![Page 6: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/6.jpg)
Nelson Senna
Twitter: @nelson_senna Github: nelsonsar Slides: http://bit.ly/nelsonsar Blog: http://nelsonsar.github.io
![Page 7: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/7.jpg)
O que é um teste?
![Page 8: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/8.jpg)
1 <?php 2 3 namespace App; 4 5 class Download 6 { 7 public function fromUrl($fromUrl, $toFile) 8 { 9 $contents = file_get_contents($fromUrl); 10 // var_dump($contents); 11 $bytes = file_put_contents( 12 $toFile, 13 $contents 14 ); 15 // var_dump($bytes); 16 return $bytes; 17 } 18 }
![Page 9: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/9.jpg)
1 <?php 2 3 namespace App; 4 5 class Download 6 { 7 public function fromUrl($fromUrl, $toFile) 8 { 9 $contents = file_get_contents($fromUrl); 10 // var_dump($contents); 11 $bytes = file_put_contents( 12 $toFile, 13 $contents 14 ); 15 // var_dump($bytes); 16 return $bytes; 17 } 18 }
![Page 10: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/10.jpg)
1 <?php 2 3 namespace App; 4 5 class Download 6 { 7 public function fromUrl($fromUrl, $toFile) 8 { 9 $contents = file_get_contents($fromUrl); 10 // var_dump($contents); 11 $bytes = file_put_contents( 12 $toFile, 13 $contents 14 ); 15 // var_dump($bytes); 16 return $bytes; 17 } 18 }
![Page 11: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/11.jpg)
1 <?php 2 3 namespace App; 4 5 class DownloadTest extends \PHPUnit_Framework_TestCase 6 { 7 const DESTINATION_FILE = '/tmp/test-file'; 8 9 public function tearDown() 10 { 11 unlink(self::DESTINATION_FILE); 12 } 13 14 public function testDownloadCreatesTheFile() 15 { 16 $file = self::DESTINATION_FILE; 17 $this->assertFileNotExists($file); 18 19 $downloader = new Download; 20 $url = 'http://example.org'; 21 $bytesWritten = $downloader->fromUrl($url, $file); 22 23 $this->assertGreaterThan(0, $bytesWritten); 24 $this->assertFileExists($file); 25 } 26 }
![Page 12: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/12.jpg)
1 <?php 2 3 namespace App; 4 5 class DownloadTest extends \PHPUnit_Framework_TestCase 6 { 7 const DESTINATION_FILE = '/tmp/test-file'; 8 9 public function tearDown() 10 { 11 unlink(self::DESTINATION_FILE); 12 } 13 14 public function testDownloadCreatesTheFile() 15 { 16 $file = self::DESTINATION_FILE; 17 $this->assertFileNotExists($file); 18 19 $downloader = new Download; 20 $url = 'http://example.org'; 21 $bytesWritten = $downloader->fromUrl($url, $file); 22 23 $this->assertGreaterThan(0, $bytesWritten); 24 $this->assertFileExists($file); 25 } 26 }
![Page 13: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/13.jpg)
Diferentes níveis de teste
1. Unitário (white-box)
2. Integração (white-box, black-box)
3. Acceptance (black-box)
![Page 14: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/14.jpg)
O que é TDD?
![Page 15: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/15.jpg)
–Ron Jeffries
“Código limpo que funciona.”
![Page 16: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/16.jpg)
–Wikipedia: Test-driven development
“… metodologia que se baseia na repetição de ciclos muito curtos de desenvolvimento.”
https://en.wikipedia.org/wiki/Test-driven_development
![Page 17: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/17.jpg)
Um ciclo
![Page 18: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/18.jpg)
Um ciclo
1. Criar um teste (RED)
![Page 19: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/19.jpg)
Um ciclo
1. Criar um teste (RED)
2. Fazer uma mudança pequena (GREEN)
![Page 20: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/20.jpg)
Um ciclo
1. Criar um teste (RED)
2. Fazer uma mudança pequena (GREEN)
3. Refactor
![Page 21: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/21.jpg)
–Kent Beck / Nat Pryce
“O TDD não garante boa arquitetura. Ele dá um retorno imediato do que, provavelmente, é uma
má arquitetura.”
![Page 22: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/22.jpg)
Por que usar TDD?
![Page 23: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/23.jpg)
Por que usar TDD?
• Evitar que defeito vire falha
• Evitar o “stress loop”
• Aumenta coesão, diminui acoplamento
• É uma forma de documentação
![Page 24: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/24.jpg)
Mão na massa?
![Page 25: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/25.jpg)
O que iremos fazer?
![Page 26: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/26.jpg)
![Page 27: Advanced live testing em tempo real](https://reader034.vdocuments.us/reader034/viewer/2022042816/558bc39cd8b42ace4b8b465c/html5/thumbnails/27.jpg)
Iterações
1. Falha ao salvar um e-mail na newsletter.
2. Validação de email ao salvar.
3. Salvar um e-mail.