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……………….
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
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);}};
}