advanced live testing em tempo real

Post on 25-Jun-2015

188 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

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

Advanced Live TestingAugusto Pascutti / Nelson Senna

Advanced Live TestingAugusto Pascutti / Nelson Senna

Nossa experiência com TDDAugusto Pascutti / Nelson Senna

Os pilotos

Augusto Pascutti

Twitter: @augustohp Github: augustohp Slides: http://bit.ly/augustohp Blog: http://augustopascutti.com

Nelson Senna

Twitter: @nelson_senna Github: nelsonsar Slides: http://bit.ly/nelsonsar Blog: http://nelsonsar.github.io

O que é um teste?

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 }

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 }

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 }

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 }

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 }

Diferentes níveis de teste

1. Unitário (white-box)

2. Integração (white-box, black-box)

3. Acceptance (black-box)

O que é TDD?

–Ron Jeffries

“Código limpo que funciona.”

–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

Um ciclo

Um ciclo

1. Criar um teste (RED)

Um ciclo

1. Criar um teste (RED)

2. Fazer uma mudança pequena (GREEN)

Um ciclo

1. Criar um teste (RED)

2. Fazer uma mudança pequena (GREEN)

3. Refactor

–Kent Beck / Nat Pryce

“O TDD não garante boa arquitetura. Ele dá um retorno imediato do que, provavelmente, é uma

má arquitetura.”

Por que usar TDD?

Por que usar TDD?

• Evitar que defeito vire falha

• Evitar o “stress loop”

• Aumenta coesão, diminui acoplamento

• É uma forma de documentação

Mão na massa?

O que iremos fazer?

Iterações

1. Falha ao salvar um e-mail na newsletter.

2. Validação de email ao salvar.

3. Salvar um e-mail.

http://github.com/PHPSP/Jarbas

top related