Observations on the testing culture of Test Driven Development

Doug Arcuri
Mar 2, 2018 · 14 min read
Image for post
Image for post
A homage to “purple” wires installed by IBM field engineers decades ago. They were yellow.
[KISS, Quality, YAGNI, ...] + [Testing, Specs, ...] == [TDD, ...]

TDD, Studies, And Professionalism

Image for post
Image for post
An impactful visual is taken from the Helsinki report.

1. TDD Commands Verbalizing An Approach

2. TDD Commands Muscle Memory

3. TDD Commands Thinking At Least Slightly Forward

// A Test List
// "" -> does not validate
// "a" -> does not validate
// "aa" -> validates
// "racecar" -> validates
// "Racecar" -> validates
// print the validation
// have a blueberry ale

4. TDD Demands Communication With Others

5. TDD Demands Iterative Architecture

6: TDD Reveals Unit Test Frailty And Degenerative Implementation

// Not an imperfect palindrome.@Test
fun `Given "", then it does not validate`() {
"".validate().shouldBeFalse()
}
@Test
fun `Given "a", then it does not validate`() {
"a".validate().shouldBeFalse()
}
@Test
fun `Given "aa", then it validates`() {
"aa".validate().shouldBeTrue()
}
@Test
fun `Given "abba", then it validates`() {
"abba".validate().shouldBeTrue()
}
@Test
fun `Given "racecar", then it validates`() {
"racecar".validate().shouldBeTrue()
}
@Test
fun `Given "Racecar", then it validates`() {
"Racecar".validate().shouldBeTrue()
}
// Too generic of a solve based on tests providedfun String.validate() = if (isEmpty() || length == 1) false else toLowerCase() == toLowerCase().reversed()// Is the best implementation and solves all testsfun String.validate() = length > 1

7: TDD Reveals Assertion Completion Feedback Loop

// Print numbers 9 to 15. [OK]
// For numbers divisible by 3, print Fizz instead of the number.
// ...
@Test
fun `Given numbers, replace those divisible by 3 with "Fizz"`() {
val machine = FizzBuzz()
assertEquals(machine.print(), "?")
}
class FizzBuzz {
fun print(): String {
var output = ""
for (i in 9..15) {
output += if (i % 3 == 0) {
"Fizz "
} else "${i} "
}
return output.trim()
}
}
Expected <Fizz 10 11 Fizz 13 14 Fizz>, actual <?>.

8: TDD Reveals The Transformation Priority Premise

Image for post
Image for post
The order of the transformations. One should always lower-ordered changes.

Has TDD Taken Off?

Conclusion

Image for post
Image for post
From XP Explained. Initially, about design quality, imagine a higher threshold line.
@Test
fun `Given software, when we build, then we expect tests`() {
build(software) shoudHave tests
}


freeCodeCamp.org

This is no longer updated.

Thanks to Hazem Saleh and Danny Preussler

Doug Arcuri

Written by

Engineering Manager // New York // Writings that aim to be timeless, explore the meta on software, and invoke though. // Also see https://dev.to/solidi

freeCodeCamp.org

This is no longer updated. Go to https://freecodecamp.org/news instead

Doug Arcuri

Written by

Engineering Manager // New York // Writings that aim to be timeless, explore the meta on software, and invoke though. // Also see https://dev.to/solidi

freeCodeCamp.org

This is no longer updated. Go to https://freecodecamp.org/news instead

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store