TDD as if you Meant It: Think – Red – Green – Refactor (Episode 1)
About
TDD as if you meant it is a very strict way of writing code in a Test Driven Development approach. One needs to follow the rules below:
Guidelines
In the first episode the main focus in to respect a few guidelines:
- Guideline 1: Always start with outputs when doing an analysis
- Guideline 2: Behavior Slicing
- Guideline 3: SIMPLIFY!
- Guideline 4: Introduce only one notion (domain concept) at a time, one per test
- Guideline 5: The rule of three “only extract duplication when spotted at least three times”
- Guideline 6: Triangulation
Think
The most important thing with TDD is to think before starting to code. So I introduced this step and I am using the cycle
Think -> Red -> Green -> Refactor
We do need analysis before writing code and before using Test Driven Development!
Tests
Based on these guidelines I started writing some tests, while simplifying to the maximum the problem.
My first test is about the simplest Tic Tac Toe game: X always wins on a one by one board
@Test
public void forOneByOneBoardXAlwaysWins(){
// Arrange
String board = "one by one";
String expected = "X won";
// Production code
String gameResult = board == "one by one" ? "X won" : "Nobody won";
// Act
String actual = gameResult;
// Assert
assertEquals(expected, actual);
}
Then I started triangulating on the notion of winning
@Test
public void forTwoByTwoBoardXWinsOnLeftColumn(){
// Arrange
String board = "two by two with X on left column";
String expected = "X won";
// Production code
String gameResult = board == "two by two with X on left column" ? "X won" : "Nobody won";
// Act
String actual = gameResult;
// Assert
assertEquals(expected, actual);
}
@Test
public void forTwoByTwoBoardXWinsOnRightColumn(){
// Arrange
String board = "two by two with X on right column";
String expected = "X won";
// Production code
String gameResult = board == "two by two with X on right column" ? "X won" : "Nobody won";
// Act
String actual = gameResult;
// Assert
assertEquals(expected, actual);
}
Video
Check the video below with the first episode:
What’s Next?
Check the next episode on TDD as if you Meant it here: http://blog.adrianbolboaca.ro/evolutionary-design
On the same page you can find more ideas on Evolutionary Design.
Credits
Many thanks to Keith Braithwaite for creating the concept of TDD as if you Meant It
Teddy bear thanks to Erik Talboom for all the pairing, discussions that lead to so many twists we discovered together with TDD as if you Meant It.
Special regards to JB Rainsberger for the fun pairing we did using TDD as if you Meant It

Nice series, Adi 🙂 Looking forward to the next episode. By the way, one of the “rules” of TDD is to write the minimum amount of production code to make your failing test pass. In this sense how to justify the “Nobody won” else-block? After all it isn’t actually exercised. Cheers :)
Adi? 🙂
Thanks for the comment Pawel! You are right, ‘that area is not tested. But when I will add a focused test on the other branch and extract the method, then the resulted method will be tested as it should.