SlideShare a Scribd company logo
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

More Related Content

Similar to Stop testing start designing

Refactoring at Large
Refactoring at LargeRefactoring at Large
Refactoring at Large
Danilo Sato
 
Enterprise Data Warehouse
Enterprise Data WarehouseEnterprise Data Warehouse
Enterprise Data Warehouse
SaimaMehdi
 
Salesforce creating on_demand_apps
Salesforce creating on_demand_appsSalesforce creating on_demand_apps
Salesforce creating on_demand_apps
willsco
 
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
Vinh Nguyen
 
Jakarta struts
Jakarta strutsJakarta struts
Jakarta struts
saraswatankit
 
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
sividocz
 
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 categories
Dũ 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_1991
praveen188668
 
ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0ScalaCheck Cookbook v1.0
ScalaCheck Cookbook v1.0
Oscar 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 Development
Marco 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.doc
sividocz
 

Similar to 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
 
Jakarta struts
Jakarta strutsJakarta struts
Jakarta struts
 
Jakarta strutslive
Jakarta strutsliveJakarta strutslive
Jakarta strutslive
 
Struts Live
Struts LiveStruts Live
Struts Live
 
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
 

Recently uploaded

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 

Recently uploaded (20)

A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 

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…