SlideShare une entreprise Scribd logo
1  sur  43
STOP TESTING – START
DESIGNING
Transform your Unit
Testing practice
HOW DO YOU
DESIGN WITH
UNIT TEST ?
https://www.flickr.com/photos/through-rimas-
WHAT DOES IT MEAN TO DESIGN ?
………………… goal ……………………………………..
……………… object ……………………………………...
…requirements ………… and constraints …………………
……………………………………………………………...
……………………………………..environment…………..
……………………………………………………………...
…aesthetic………………………………………………….
…………………………………..functional……………….
AGENDA
 Design Tools : CRC Cards
 Testing Tool : Code coverge
 Documentation Tool : Sequence
diagram
 A few Tips
CRC CARDS
https://www.flickr.com/photos/teamaskins/
Class
Responsibilities
•
•
•
Collaborato
rs
•
•
Shipment
Responsibilities:
• Records Date
• Verify
Availability
• Trigger
invoices
Collaborato
rs:
• Stock
• Accounti
ng
public class XxxxxxxTest {
}
public class ShipmentTest {
Shipment shipment = new Shipment();
}
Class
public class ShipmentTest {
@Mock Stock stock;
@Mock Accounting accountant;
Shipment shipment = new Shipment(stock, accountant);
}
Collaborator
s
Class
public class ShipmentTest {
@Mock Stock stock;
@Mock Accounting accountant;
Shipment shipment = new Shipment(stock, accountant);
@Test void testRecordsDate() {
…
}
@Test void testVerifyAvailability() {
…
}
@Test void testTriggerInvoice() {
…
}
}
Collaborator
s
Class
Responsibilit
ies
THINK ABOUT RESPONSIBILITIES
https://www.flickr.com/photos/70554893@N00/
CODE COVERAGE – A DESIGN TOOL
https://www.tasktop.com/blog/incremental-code-coverage-
Responsibilities :
• Zoom
• Adjust to metric
• Adjust to large
scale
Choice =>
Responsibility
https://www.flickr.com/photos/dheeranet/
RESPONSIBILITY
TESTING
SCENARIO BASED TESTING
https://www.flickr.com/photos/dh
@Test(expect=UnavailableProduct.class)
public void testVerifyAvailability() {
Order order = aSampleOrder().unavailable();
expect(stock).isAvailable(); will(returnValue(false));
shipment.ship(order)
}
@Test(expect=UnavailableProduct.class)
public void testShipUnavailableOrder() {
Order order = aSampleOrder().unavailable();
expect(stock).isAvailable(); will(returnValue(false));
shipment.ship(order)
}
Responsibili
ty
Scenario
SEQUENCE /
COLLABORAT
ION
DIAGRAM
https://www.flickr.com/photos/12665453
UN SEQUENCE
Caller prepare order
Collaborators : Stock, accounting
call ship(order)
Shipment call stock.isAvailable() [Expectation]
Shipment call accounting.sendInvoice [Expectation]
My sequence diagram is a test …. My test is a sequence diagram…
Stock stock = mock(Stock.class);
Accounting acc = mock(Accounting.class);
Shipping shipment = new Shipping(stock,acc);
public void testShipOrder() {
shipment.ship(order);
verify(stock).isAvailable(order);
verify(acc).sendInvoice(order);
}
TEST IS A
DOCUMENTAT
ION
THE CODE MUST WORK
NOW
AND LATER
Developer
responsibility
https://www.flickr.com/photos/joans
orolla/
WHAT DOES IT MEAN TO DESIGN ?
………………… goal ……………………………………..
……………… object ……………………………………...
…requirements ………… and constraints …………………
……………………………………………………………...
……………………………………..environment…………..
……………………………………………………………...
…aesthetic………………………………………………….
…………………………………..functional……………….
DESIGN -
AESTHETIC
Use Refactring
• Keep functional aspects
• Keep your design choice
unchanged
• Foccus on aesthetic
https://www.flickr.com/photos/59810064
@N07/
DESIGN - ENVIRONMENT
Object is designed
for an environment
Unit test is a
documentation of
that environment
https://www.flickr.com/photos/dms
umon/
UNIT TESTING TIPS
https://www.flickr.com/photos/phalene
NO NOISE Unit test is a
documentation
https://www.flickr.com/photos/dalbera
/
NO NOISE – PRIVATE IS USELESS
public class ShipmentTest {
@Mock private Stock stock;
@Mock private Accounting accountant;
private Shipment shipment = new Shipment(stock, accountant);
…
}
NO NOISE – PRIVATE IS USELESS
public class ShipmentTest {
@Mock private Stock stock;
@Mock private Accounting accountant;
private Shipment shipment = new Shipment(stock, accountant);
…
}
NO NOISE – PRIVATE IS USELESS
public class ShipmentTest {
@Mock Stock stock;
@Mock Accounting accountant;
Shipment shipment = new Shipment(stock, accountant);
…
}
NO NOISE – LIGHT SETUP
public class ShipmentTest {
Stock stock;
Accounting accountant;
Shipment shipment;
@Before
public setUp() {
stock = mock(Stock.class);
accountant = mock(Accounting.class);
shipment = new Shipment(stock, accountant);
}
}
NO NOISE – LIGHT SETUP
public class ShipmentTest {
Stock stock = mock(Stock.class);
Accounter accounter = mock(Accounter.class);
Shipment shipment = new Shipment(stock, accounter);
@Before
public setUp() {
stock = mock(Stock.class);
accounter = mock(Accounter.class);
shipment = new Shipment(stock, accounter);
}
}
NO NOISE – LIGHT SETUP
public class ShipmentTest {
Stock stock = mock(Stock.class);
Accounter accounter = mock(Accounter.class);
Shipment shipment = new Shipment(stock, accounter);
}
Unit Test is
a Design
Description
https://www.flickr.com/photos/summe
NO NOISE – LIGHT SETUP
public class ShipmentTest {
@Before
public setUp() {
createOrderFile();
}
}
NO NOISE – LIGHT SETUP
public class ShipmentTest {
@Before
public setUp() {
createOrderFile();
}
}
NO NOISE – LIGHT SETUP
public class ShipmentTest {
{ createOrderFile(); }
}
NO NOISE – LIGHT LIST SETUP
public class ShipmentTest {
List products = new LinkedList();
{
products.add(FOO);
products.add(BAR);
}
}
NO NOISE – LIGHT LIST SETUP
public class ShipmentTest {
List products = new LinkedList();
{{
products.add(FOO);
products.add(BAR);
}};
}
NO NOISE – LIGHT LIST SETUP
public class ShipmentTest {
List products = new LinkedList() {{add(FOO); add(BAR);}};
}
CREATE DATA
https://www.flickr.com/photos/pictures-
of-money/
Contract contract = aContract().createdIn(2010).at(BRUXELLES);
Contract contract = aContract().covering(
aHouse().with(aGarage(), aCellar())
).value();
CREATE DATA – BUILDER METHODS
COMMUNICATE
• Clear message
• No noise
• Foccus on your design
https://www.flickr.com/photos/50228879
CONCLUSION
Think about Responsibilities
Think to Unit test as a Documentation
You are responsible for your
code,
now,
and later…
@gscokart
https://www.linkedin.com/in/gsc
okart

Contenu connexe

Similaire à Stop testing start designing

Refactoring at Large
Refactoring at LargeRefactoring at Large
Refactoring at LargeDanilo Sato
 
Enterprise Data Warehouse
Enterprise Data WarehouseEnterprise Data Warehouse
Enterprise Data WarehouseSaimaMehdi
 
Salesforce creating on_demand_apps
Salesforce creating on_demand_appsSalesforce creating on_demand_apps
Salesforce creating on_demand_appswillsco
 
MFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document GuideMFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document GuideVinh Nguyen
 
A Comparison Of Expression Of Tenses Between English And Vietnamese.doc
A Comparison Of Expression Of Tenses Between English And Vietnamese.docA Comparison Of Expression Of Tenses Between English And Vietnamese.doc
A Comparison Of Expression Of Tenses Between English And Vietnamese.docsividocz
 
TDavis_SkynaxDataWebServicesGuide
TDavis_SkynaxDataWebServicesGuideTDavis_SkynaxDataWebServicesGuide
TDavis_SkynaxDataWebServicesGuideToni Davis
 
All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...
All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...
All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...Antti Koski
 
New project information sheet
New project information sheetNew project information sheet
New project information sheetMpho Seboane
 
Vic broquard c++ for computer science and engineering 2006
Vic broquard c++ for computer science and engineering 2006Vic broquard c++ for computer science and engineering 2006
Vic broquard c++ for computer science and engineering 2006Souvik Maity
 
CA Service Desk Administrator Guide with Examples
CA Service Desk Administrator Guide with ExamplesCA Service Desk Administrator Guide with Examples
CA Service Desk Administrator Guide with ExamplesArshad Havaldar
 
Ibm spss categories
Ibm spss categoriesIbm spss categories
Ibm spss categoriesDũ Lê Anh
 
Borland c++ version_3.0_users_guide_1991
Borland c++ version_3.0_users_guide_1991Borland c++ version_3.0_users_guide_1991
Borland c++ version_3.0_users_guide_1991praveen188668
 
ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0Oscar Renalias
 
Student Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project Development
Student Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project DevelopmentStudent Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project Development
Student Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project DevelopmentMarco Enrique Ramos Castillo
 
A Cross-Culture Study On Greeting Ways Of Vietnam And American People.doc
A Cross-Culture Study On Greeting Ways Of Vietnam And American People.docA Cross-Culture Study On Greeting Ways Of Vietnam And American People.doc
A Cross-Culture Study On Greeting Ways Of Vietnam And American People.docsividocz
 

Similaire à Stop testing start designing (20)

Refactoring at Large
Refactoring at LargeRefactoring at Large
Refactoring at Large
 
Enterprise Data Warehouse
Enterprise Data WarehouseEnterprise Data Warehouse
Enterprise Data Warehouse
 
Acro_js_guide
Acro_js_guideAcro_js_guide
Acro_js_guide
 
Salesforce creating on_demand_apps
Salesforce creating on_demand_appsSalesforce creating on_demand_apps
Salesforce creating on_demand_apps
 
MFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document GuideMFG/PRO QAD Reporting Framework Document Guide
MFG/PRO QAD Reporting Framework Document Guide
 
Struts Live
Struts LiveStruts Live
Struts Live
 
Jakarta strutslive
Jakarta strutsliveJakarta strutslive
Jakarta strutslive
 
Jakarta struts
Jakarta strutsJakarta struts
Jakarta struts
 
A Comparison Of Expression Of Tenses Between English And Vietnamese.doc
A Comparison Of Expression Of Tenses Between English And Vietnamese.docA Comparison Of Expression Of Tenses Between English And Vietnamese.doc
A Comparison Of Expression Of Tenses Between English And Vietnamese.doc
 
TDavis_SkynaxDataWebServicesGuide
TDavis_SkynaxDataWebServicesGuideTDavis_SkynaxDataWebServicesGuide
TDavis_SkynaxDataWebServicesGuide
 
All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...
All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...
All my old anttikoski.fi blog posts about Adobe Analytics and Adobe Launch fr...
 
New project information sheet
New project information sheetNew project information sheet
New project information sheet
 
Vic broquard c++ for computer science and engineering 2006
Vic broquard c++ for computer science and engineering 2006Vic broquard c++ for computer science and engineering 2006
Vic broquard c++ for computer science and engineering 2006
 
CA Service Desk Administrator Guide with Examples
CA Service Desk Administrator Guide with ExamplesCA Service Desk Administrator Guide with Examples
CA Service Desk Administrator Guide with Examples
 
TI Navigator Help
TI Navigator HelpTI Navigator Help
TI Navigator Help
 
Ibm spss categories
Ibm spss categoriesIbm spss categories
Ibm spss categories
 
Borland c++ version_3.0_users_guide_1991
Borland c++ version_3.0_users_guide_1991Borland c++ version_3.0_users_guide_1991
Borland c++ version_3.0_users_guide_1991
 
ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0
 
Student Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project Development
Student Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project DevelopmentStudent Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project Development
Student Manual _ ABT-CCP-143-TSM _ RSLogix 5000, Level 3 _ Project Development
 
A Cross-Culture Study On Greeting Ways Of Vietnam And American People.doc
A Cross-Culture Study On Greeting Ways Of Vietnam And American People.docA Cross-Culture Study On Greeting Ways Of Vietnam And American People.doc
A Cross-Culture Study On Greeting Ways Of Vietnam And American People.doc
 

Dernier

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 

Dernier (20)

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 

Stop testing start designing

  • 1. STOP TESTING – START DESIGNING Transform your Unit Testing practice
  • 2. HOW DO YOU DESIGN WITH UNIT TEST ? https://www.flickr.com/photos/through-rimas-
  • 3. WHAT DOES IT MEAN TO DESIGN ? ………………… goal …………………………………….. ……………… object ……………………………………... …requirements ………… and constraints ………………… ……………………………………………………………... ……………………………………..environment………….. ……………………………………………………………... …aesthetic…………………………………………………. …………………………………..functional……………….
  • 4. AGENDA  Design Tools : CRC Cards  Testing Tool : Code coverge  Documentation Tool : Sequence diagram  A few Tips
  • 7. Shipment Responsibilities: • Records Date • Verify Availability • Trigger invoices Collaborato rs: • Stock • Accounti ng
  • 9. public class ShipmentTest { Shipment shipment = new Shipment(); } Class
  • 10. public class ShipmentTest { @Mock Stock stock; @Mock Accounting accountant; Shipment shipment = new Shipment(stock, accountant); } Collaborator s Class
  • 11. public class ShipmentTest { @Mock Stock stock; @Mock Accounting accountant; Shipment shipment = new Shipment(stock, accountant); @Test void testRecordsDate() { … } @Test void testVerifyAvailability() { … } @Test void testTriggerInvoice() { … } } Collaborator s Class Responsibilit ies
  • 13. CODE COVERAGE – A DESIGN TOOL https://www.tasktop.com/blog/incremental-code-coverage- Responsibilities : • Zoom • Adjust to metric • Adjust to large scale
  • 16. @Test(expect=UnavailableProduct.class) public void testVerifyAvailability() { Order order = aSampleOrder().unavailable(); expect(stock).isAvailable(); will(returnValue(false)); shipment.ship(order) } @Test(expect=UnavailableProduct.class) public void testShipUnavailableOrder() { Order order = aSampleOrder().unavailable(); expect(stock).isAvailable(); will(returnValue(false)); shipment.ship(order) } Responsibili ty Scenario
  • 18. UN SEQUENCE Caller prepare order Collaborators : Stock, accounting call ship(order) Shipment call stock.isAvailable() [Expectation] Shipment call accounting.sendInvoice [Expectation] My sequence diagram is a test …. My test is a sequence diagram… Stock stock = mock(Stock.class); Accounting acc = mock(Accounting.class); Shipping shipment = new Shipping(stock,acc); public void testShipOrder() { shipment.ship(order); verify(stock).isAvailable(order); verify(acc).sendInvoice(order); }
  • 20. THE CODE MUST WORK NOW AND LATER Developer responsibility https://www.flickr.com/photos/joans orolla/
  • 21. WHAT DOES IT MEAN TO DESIGN ? ………………… goal …………………………………….. ……………… object ……………………………………... …requirements ………… and constraints ………………… ……………………………………………………………... ……………………………………..environment………….. ……………………………………………………………... …aesthetic…………………………………………………. …………………………………..functional……………….
  • 22. DESIGN - AESTHETIC Use Refactring • Keep functional aspects • Keep your design choice unchanged • Foccus on aesthetic https://www.flickr.com/photos/59810064 @N07/
  • 23. DESIGN - ENVIRONMENT Object is designed for an environment Unit test is a documentation of that environment https://www.flickr.com/photos/dms umon/
  • 25. NO NOISE Unit test is a documentation https://www.flickr.com/photos/dalbera /
  • 26. NO NOISE – PRIVATE IS USELESS public class ShipmentTest { @Mock private Stock stock; @Mock private Accounting accountant; private Shipment shipment = new Shipment(stock, accountant); … }
  • 27. NO NOISE – PRIVATE IS USELESS public class ShipmentTest { @Mock private Stock stock; @Mock private Accounting accountant; private Shipment shipment = new Shipment(stock, accountant); … }
  • 28. NO NOISE – PRIVATE IS USELESS public class ShipmentTest { @Mock Stock stock; @Mock Accounting accountant; Shipment shipment = new Shipment(stock, accountant); … }
  • 29. NO NOISE – LIGHT SETUP public class ShipmentTest { Stock stock; Accounting accountant; Shipment shipment; @Before public setUp() { stock = mock(Stock.class); accountant = mock(Accounting.class); shipment = new Shipment(stock, accountant); } }
  • 30. NO NOISE – LIGHT SETUP public class ShipmentTest { Stock stock = mock(Stock.class); Accounter accounter = mock(Accounter.class); Shipment shipment = new Shipment(stock, accounter); @Before public setUp() { stock = mock(Stock.class); accounter = mock(Accounter.class); shipment = new Shipment(stock, accounter); } }
  • 31. NO NOISE – LIGHT SETUP public class ShipmentTest { Stock stock = mock(Stock.class); Accounter accounter = mock(Accounter.class); Shipment shipment = new Shipment(stock, accounter); }
  • 32. Unit Test is a Design Description https://www.flickr.com/photos/summe
  • 33. NO NOISE – LIGHT SETUP public class ShipmentTest { @Before public setUp() { createOrderFile(); } }
  • 34. NO NOISE – LIGHT SETUP public class ShipmentTest { @Before public setUp() { createOrderFile(); } }
  • 35. NO NOISE – LIGHT SETUP public class ShipmentTest { { createOrderFile(); } }
  • 36. NO NOISE – LIGHT LIST SETUP public class ShipmentTest { List products = new LinkedList(); { products.add(FOO); products.add(BAR); } }
  • 37. NO NOISE – LIGHT LIST SETUP public class ShipmentTest { List products = new LinkedList(); {{ products.add(FOO); products.add(BAR); }}; }
  • 38. NO NOISE – LIGHT LIST SETUP public class ShipmentTest { List products = new LinkedList() {{add(FOO); add(BAR);}}; }
  • 40. Contract contract = aContract().createdIn(2010).at(BRUXELLES); Contract contract = aContract().covering( aHouse().with(aGarage(), aCellar()) ).value(); CREATE DATA – BUILDER METHODS
  • 41. COMMUNICATE • Clear message • No noise • Foccus on your design https://www.flickr.com/photos/50228879
  • 42. CONCLUSION Think about Responsibilities Think to Unit test as a Documentation You are responsible for your code, now, and later…