SlideShare a Scribd company logo
1 of 53
Integração Contínua Terra Ágil Nov/2010
IC Integração Contínua “Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.” http://www.martinfowler.com/articles/continuousIntegration.html
IC IC @ Atlas :  Testes: Unidade/Funcionais (Integração)
IC Bottom Up!  Injeção de Dependência Mocks TDD Integracao Continua / Hudson Conclusão
IC Dependency Injection Design Pattern Reduzir acoplamento Vários tipos (constructor injection, setter injection, interface injection)
IC Dependency Injection class HardcodedWorkflow { 	public void execute() 	{ 	// do LOTS of workflow stuff 		... 		FileSenderService service =  new FileSenderService(fileName, "This is a message");  		service.send(); 		// do LOTS more workflow stuff 		... } }
IC Dependency Injection class FileSenderService implements ISenderService { 	private String message; 	private File file; 	public FileSenderService(String fileName, String message) 	{ 		this.parameter = message; 		this.file = File.open(fileName); 	} 	public void send() 	{ 		file.write(message); 	} }
IC Dependency Injection class EmailSenderService implements ISenderService { 	... 	public void send() 	{ 		smtpLib.send(emailAddress, message); 	} }
IC É só um “IF”
IC É só um “IF”
IC Dependency Injection class HardcodedWorkflow { 	public void execute(int delivery) 	{ 	// do LOTS of workflow stuff ... ISenderService service; if(delivery == MsgDelivery.FILE) { 			service = new FileSenderService("This is a message"); } else if(delivery == MsgDelivery.EMAIL) { 			service = new EmailSenderService("This is a slightly different message"); }  service.send(); // do LOTS more workflow stuff ... 	} }
IC 2 meses depois ...
IC Dependency Injection 	... if(delivery == MsgDelivery.FILE) { 		service = new FileSenderService("This is a message");  	} else if(delivery == MsgDelivery.EMAIL) { 		service = new EmailSenderService(userAddress, "This is a slightly different message""); 	} else if(delivery == MsgDelivery.ADMINISTRATOR_EMAIL) { 		service = new EmailSenderService(adminAddress, "SUDO this is a message!!!"); 	} else if(delivery == MsgDelivery.ABU_DHABI_BY_AIR_MAIL) { 		service = new AbuDhabiAirMailSenderService("Hello, Mama"); 	} else if(delivery == MsgDelivery.DEVNULL) { 		service = new DevNullSenderService("Hello, is anybody in there??!?!"); // why do I care?!?! 	} ...
IC 2 Anos depois ...
IC
IC Dependency Injection To The Rescue!!! class FlexibleWorkflow { 	private ISenderService service; 	public FlexibleWorkflow(ISenderService service) // << "LOOSE COUPLING" 	{ 		this.service = service; 	} 	public void execute() 	{ 		// do LOTS of workflow stuff 		... this.service.send(); 		// do LOTS more workflow stuff 		... 	} }
IC Dependency Injection To The Rescue!!! class FileWorkflowController { 	public void handleRequest() 	{ 		ISenderService service =  			new FileSenderService("This is a message."); // << "TIGHT COUPLING!!!" 		FlexibleWorkflow workflow =  			new FlexibleWorkflow(service); 		workflow.execute(); 	} }
IC Dependency Injection To The Rescue!!! class EmailWorkflowController { 	public void handleRequest() 	{ 		ISenderService service =  			new EmailSenderService(getUserEmail(), "This is a slightly different message."); 		FlexibleWorkflow workflow =  			new FlexibleWorkflow(service); 		workflow.execute(); 	} }
IC Dependency Injection Ok, legal, mas o quê isso tem a ver com o pastel?!?!
IC Testes com Mocks!!! class FlexibleWorkflowTest extends TestCase { 	// millions of other tests 	... 	public void testMessageSend() 	{ 		ISenderService mockService =  			new MockSenderService(); 		FlexibleWorkflow workflow =  			new FlexibleWorkflow(mockService); 		workflow.execute(); 		assertTrue(workflow.getResult(), true); mockService.assertCalled("send"); 		// millions of other assertions 		... 	} }
IC Mock Objects Mocks aren’t Stubs! http://martinfowler.com/articles/mocksArentStubs.html
IC Stubs 	ISenderService stubService =  new StubService(); 	FlexibleWorkflow workflow = new FlexibleWorkflow(stubService); 	workflow.execute(); // nada mais a fazer, o stub nao provê nenhuma informacao
IC Stubs
IC Mock Objects Estilo diferente de testes
IC Mock Objects Inspecionar comportamento class FlexibleWorkflowTestextends TestCase { 	public void testMessageSend() 	{ 		ISenderService mockService =  			new MockSenderService(); 		FlexibleWorkflow workflow =  			new FlexibleWorkflow(mockService); 		workflow.execute(); 		assertTrue(workflow.getResult(), true); mockService.assertCalled("send"); 		// millions of other assertions 		... 	} }
IC Mock Objects Simulando condições de erro public void testMessageSendError() { 	ISenderService mockService =  		new MockSenderService(); 	// mock lanca "SmtpTimeoutException" quando 	// metodo "send" e chamado 	mockService.setSideEffect("send",  		new SideEffect() {  void run () { throw new SmtpTimeoutException();} }); 	FlexibleWorkflow workflow =  		new FlexibleWorkflow(mockService); 	try { 		workflow.execute(); 	} catch(Exception e) { 		assertFail(); } } interface SideEffect { 	void run(); }
IC Mock Objects Mocks sao agentes do codigo de teste
IC TDD “You have probably heard a few talks or read a few articles where test driven development is depicted as a magic unicorn that watches over your software and makes everybody happy.”
IC TDD “ Well, about 18.000 lines of ‘magic unicorn’ code later, I'd like to put things into perspective.”
IC TDD “The truth is, test driven development is a huge pain in the ass.”
IC TDD “But do you know what sucks more? The liability that comes without those tests.” http://debuggable.com/posts/test-driven-development-at-transloadit:4cc892a7-b9fc-4d65-bb0c-1b27cbdd56cb
IC TDD Ok, “Test First” ... ... mas por onde eu começo?!?!
IC TDD Ok, “Test First” ... ... mas por onde eu começo?!?!
IC TDD Implementar mínimo necessário para o teste FALHAR.
IC TDD Implementar mínimo necessário para o teste FALHAR. class Math { 	public int sum(int a, int b)  	{ thrownew NotImplementedException(); 	} } class MathTest extends TestCase { 	public void testSum() 	{ Math m = new Math(); 		assertEquals(m.sum(1,2), 3); 	} }
IC TDD Vantagens
IC TDD Vantagens Código é testável “por natureza”.
IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências.
IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências. Cobertura de Código.
IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências. Cobertura de Código. Design gera interfaces (de código) mais “amigáveis”.
IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências. Cobertura de Código. Design gera interfaces (de código) mais “amigáveis”. TDD não tem “ciúminho”.
IC TDD Desvantagens
IC TDD Desvantagens Na 1a. vez, prepare-se para errar.
IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito.
IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda!
IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda! Nada é de graça (No Unicorns)
IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda! Nada é de graça (No Unicorns) Código legado
IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda! Nada é de graça (No Unicorns) Código legado É um “pé no saco”
IC Build “On-Commit” Build Noturno Testes Artefatos Radiadores De Informação
IC Hudson e o “Gremlin”
IC Hudson e o “Gremlin” Dificuldades Makefiles Ambiente
Conclusão There’s no Free Lunch ... ... and no Silver Bullet! Baby Steps! Purismo não leva a lugar nenhum Ferramentas adequadas
Hudson Q&A diego.pereira@corp.terra.com.br

More Related Content

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Terra Ágil - Integração Contínua

  • 2. IC Integração Contínua “Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.” http://www.martinfowler.com/articles/continuousIntegration.html
  • 3. IC IC @ Atlas : Testes: Unidade/Funcionais (Integração)
  • 4. IC Bottom Up! Injeção de Dependência Mocks TDD Integracao Continua / Hudson Conclusão
  • 5. IC Dependency Injection Design Pattern Reduzir acoplamento Vários tipos (constructor injection, setter injection, interface injection)
  • 6. IC Dependency Injection class HardcodedWorkflow { public void execute() { // do LOTS of workflow stuff ... FileSenderService service = new FileSenderService(fileName, "This is a message"); service.send(); // do LOTS more workflow stuff ... } }
  • 7. IC Dependency Injection class FileSenderService implements ISenderService { private String message; private File file; public FileSenderService(String fileName, String message) { this.parameter = message; this.file = File.open(fileName); } public void send() { file.write(message); } }
  • 8. IC Dependency Injection class EmailSenderService implements ISenderService { ... public void send() { smtpLib.send(emailAddress, message); } }
  • 9. IC É só um “IF”
  • 10. IC É só um “IF”
  • 11. IC Dependency Injection class HardcodedWorkflow { public void execute(int delivery) { // do LOTS of workflow stuff ... ISenderService service; if(delivery == MsgDelivery.FILE) { service = new FileSenderService("This is a message"); } else if(delivery == MsgDelivery.EMAIL) { service = new EmailSenderService("This is a slightly different message"); } service.send(); // do LOTS more workflow stuff ... } }
  • 12. IC 2 meses depois ...
  • 13. IC Dependency Injection ... if(delivery == MsgDelivery.FILE) { service = new FileSenderService("This is a message"); } else if(delivery == MsgDelivery.EMAIL) { service = new EmailSenderService(userAddress, "This is a slightly different message""); } else if(delivery == MsgDelivery.ADMINISTRATOR_EMAIL) { service = new EmailSenderService(adminAddress, "SUDO this is a message!!!"); } else if(delivery == MsgDelivery.ABU_DHABI_BY_AIR_MAIL) { service = new AbuDhabiAirMailSenderService("Hello, Mama"); } else if(delivery == MsgDelivery.DEVNULL) { service = new DevNullSenderService("Hello, is anybody in there??!?!"); // why do I care?!?! } ...
  • 14. IC 2 Anos depois ...
  • 15. IC
  • 16. IC Dependency Injection To The Rescue!!! class FlexibleWorkflow { private ISenderService service; public FlexibleWorkflow(ISenderService service) // << "LOOSE COUPLING" { this.service = service; } public void execute() { // do LOTS of workflow stuff ... this.service.send(); // do LOTS more workflow stuff ... } }
  • 17. IC Dependency Injection To The Rescue!!! class FileWorkflowController { public void handleRequest() { ISenderService service = new FileSenderService("This is a message."); // << "TIGHT COUPLING!!!" FlexibleWorkflow workflow = new FlexibleWorkflow(service); workflow.execute(); } }
  • 18. IC Dependency Injection To The Rescue!!! class EmailWorkflowController { public void handleRequest() { ISenderService service = new EmailSenderService(getUserEmail(), "This is a slightly different message."); FlexibleWorkflow workflow = new FlexibleWorkflow(service); workflow.execute(); } }
  • 19. IC Dependency Injection Ok, legal, mas o quê isso tem a ver com o pastel?!?!
  • 20. IC Testes com Mocks!!! class FlexibleWorkflowTest extends TestCase { // millions of other tests ... public void testMessageSend() { ISenderService mockService = new MockSenderService(); FlexibleWorkflow workflow = new FlexibleWorkflow(mockService); workflow.execute(); assertTrue(workflow.getResult(), true); mockService.assertCalled("send"); // millions of other assertions ... } }
  • 21. IC Mock Objects Mocks aren’t Stubs! http://martinfowler.com/articles/mocksArentStubs.html
  • 22. IC Stubs ISenderService stubService = new StubService(); FlexibleWorkflow workflow = new FlexibleWorkflow(stubService); workflow.execute(); // nada mais a fazer, o stub nao provê nenhuma informacao
  • 24. IC Mock Objects Estilo diferente de testes
  • 25. IC Mock Objects Inspecionar comportamento class FlexibleWorkflowTestextends TestCase { public void testMessageSend() { ISenderService mockService = new MockSenderService(); FlexibleWorkflow workflow = new FlexibleWorkflow(mockService); workflow.execute(); assertTrue(workflow.getResult(), true); mockService.assertCalled("send"); // millions of other assertions ... } }
  • 26. IC Mock Objects Simulando condições de erro public void testMessageSendError() { ISenderService mockService = new MockSenderService(); // mock lanca "SmtpTimeoutException" quando // metodo "send" e chamado mockService.setSideEffect("send", new SideEffect() { void run () { throw new SmtpTimeoutException();} }); FlexibleWorkflow workflow = new FlexibleWorkflow(mockService); try { workflow.execute(); } catch(Exception e) { assertFail(); } } interface SideEffect { void run(); }
  • 27. IC Mock Objects Mocks sao agentes do codigo de teste
  • 28. IC TDD “You have probably heard a few talks or read a few articles where test driven development is depicted as a magic unicorn that watches over your software and makes everybody happy.”
  • 29. IC TDD “ Well, about 18.000 lines of ‘magic unicorn’ code later, I'd like to put things into perspective.”
  • 30. IC TDD “The truth is, test driven development is a huge pain in the ass.”
  • 31. IC TDD “But do you know what sucks more? The liability that comes without those tests.” http://debuggable.com/posts/test-driven-development-at-transloadit:4cc892a7-b9fc-4d65-bb0c-1b27cbdd56cb
  • 32. IC TDD Ok, “Test First” ... ... mas por onde eu começo?!?!
  • 33. IC TDD Ok, “Test First” ... ... mas por onde eu começo?!?!
  • 34. IC TDD Implementar mínimo necessário para o teste FALHAR.
  • 35. IC TDD Implementar mínimo necessário para o teste FALHAR. class Math { public int sum(int a, int b) { thrownew NotImplementedException(); } } class MathTest extends TestCase { public void testSum() { Math m = new Math(); assertEquals(m.sum(1,2), 3); } }
  • 37. IC TDD Vantagens Código é testável “por natureza”.
  • 38. IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências.
  • 39. IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências. Cobertura de Código.
  • 40. IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências. Cobertura de Código. Design gera interfaces (de código) mais “amigáveis”.
  • 41. IC TDD Vantagens Código é testável “por natureza”. Ajuda a usar Mocks e Injeção de Dependências. Cobertura de Código. Design gera interfaces (de código) mais “amigáveis”. TDD não tem “ciúminho”.
  • 43. IC TDD Desvantagens Na 1a. vez, prepare-se para errar.
  • 44. IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito.
  • 45. IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda!
  • 46. IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda! Nada é de graça (No Unicorns)
  • 47. IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda! Nada é de graça (No Unicorns) Código legado
  • 48. IC TDD Desvantagens Na 1a. vez, prepare-se para errar. Muito. Mas aprender, mais ainda! Nada é de graça (No Unicorns) Código legado É um “pé no saco”
  • 49. IC Build “On-Commit” Build Noturno Testes Artefatos Radiadores De Informação
  • 50. IC Hudson e o “Gremlin”
  • 51. IC Hudson e o “Gremlin” Dificuldades Makefiles Ambiente
  • 52. Conclusão There’s no Free Lunch ... ... and no Silver Bullet! Baby Steps! Purismo não leva a lugar nenhum Ferramentas adequadas