Upload
pivotal
View
460
Download
0
Embed Size (px)
Citation preview
Matt Parker
@moonmaster9000
TDD(the bad parts)
BUT FIRST
A CAUTIONARY TALE
WHY TDD?
GO FAST FOREVER
GO FAST FOREVER
CLEAN CODE
GO FAST FOREVER
CLEAN CODE
REFACTORING
GO FAST FOREVER
CLEAN CODE
REFACTORING
CONFIDENCE
GO FAST FOREVER
CLEAN CODE
REFACTORING
CONFIDENCE
TESTS
GO FAST FOREVER
CLEAN CODE
REFACTORING
CONFIDENCE
TESTS TDD
PROBLEM #1:
OUTSIDE-IN BDD
1.Write acceptance test
2.Write controller test
3.Write model tests
SLOW
BRITTLE
COUPLED
FLAKY
OUTSIDE?
“Start at the outside
of what you want to
discover” - Joseph
Wilk
OUTSIDE != GUI
PROBLEM #2:
MOCKING
@RequestMapping(value = "/translate", method = REQUEST.POST)
@ResponseBody
public String show(Model model, @RequestParam String word){
return translationService.translate(word);
}
public void post_populatesModel() throws Exception {
TranslationService service = mock(TranslationService.class);
when(service.translate("apple")).thenReturn("appleway");
TranslatorController controller = new TranslatorController(service);
MockMvc mockMvc = standaloneSetup(controller).build();
mockMvc.perform(post("/translate").param("word", "apple"))
.andExpect(model().attribute("translation", "appleway"));}
}
DUMMY
STUB
SPY
MOCK
-----------------------
FAKE
THE LITTLE MOCKERblog.8thlight.com/uncle-bob/2014/05/14/TheLittleMocker.html
S.O.L.I.D.● cleancoders.com
● Agile Software Development:
Principles, Patterns, and Practices
● Pivotal Labs
HEXAGONAL TDDmoonmaster9000.github.io/hexagonal_tdd_in_ruby
PROBLEM #3:
UNIT TESTING
THREE LAWS OF
ROBOTICS TDD
1. You are not allowed to
write any production code
unless it is to make a
failing unit test pass.
2. You are not allowed to
write any more of a unit
test than is sufficient to
fail.
3. You are not allowed to
write any more production
code than is sufficient to
pass the one failing unit
test.
“Every class should be
paired with a well-
designed unit test”
“Every public method
of every class should
be paired with a well-
designed unit test”
class ClassOneTest {
@Test
public void publicMethodOne {
//...
}
@Test
public void publicMethodTwo {
//...
}
ClassOne.java
ClassOneTest.java
ClassTwo.java
ClassTwoTest.java
<REFACTORING>
DESIGN PATTERN!
class ClassOneTest {
@Test
public void publicMethodOne {
//MOVED SOME TESTS
}
//...
class ClassThreeTest {
@Test
public void publicMethodOne {
//TESTS MOVED FROM ClassOneTest
}
//...
ClassOne.java
ClassOneTest.java
ClassTwo.java
ClassTwoTest.java
ClassThree.java
ClassThreeTest.java
TEST COUPLING
DESIGN PATTERNS
GO FAST FOREVER
CLEAN CODE
REFACTORING
CONFIDENCE
TESTS TDD
GO FAST FOREVER
CLEAN CODE
REFACTORING
CONFIDENCE
TESTS TDD
GO FAST FOREVER
CLEAN CODE
REFACTORING
CONFIDENCE
TESTS TDD
“Every class should be
paired with a well-
designed unit test”
“Every class should be
paired with a well-
designed unit test”
“Every behavior should
be paired with a well-
designed unit test”
MINIMIZE SURFACE
AREA
So….
THANK YOU
QUESTIONS?