Demo
git-gamble
's demo to develop using TCRDD by doing baby steps
on a simple program
git-gamble
works with all languages and tools and editors
for this example, i use python
with pytest
and nano
export GAMBLE_TEST_COMMAND='pytest --quiet'
note : for a simpler demo, test code and production code are in the same file
Alternatively : you can also watch the slides about the demo
First TDD loop β°
Write a program that says
Hello world
First, π΄ Red phase : write a test that fails for the good reason
Alternative text
nano test_hello.py
def hello():
pass
def test_say_hello_world():
assert hello() == 'Hello world'
Then, gamble that the tests fail
git gamble --red
βοΈ Committed
Second, π’ Green phase : write the minimum code to pass the tests
Let's fake it
Alternative text
nano test_hello.py
def hello():
return 'Hello word'
Then, gamble that the tests pass
git gamble --green
β Reverted
Oh no !
I made a typo
def hello():
- return 'Hello word'
+ return 'Hello world'
Try again
Let's fake it without typo
Alternative text
nano test_hello.py
def hello():
return 'Hello world'
Gamble again that the tests pass
git gamble --green
βοΈ Committed
Yeah !
Third, π Refactor phase : Nothing to refactor yet
Then π Repeat β°
Second TDD loop βΏ
Write a program that says
Hello
to the given name when a name is given
π΄ Red phase
Alternative text
nano test_hello.py
def test_say_hello_name_given_a_name():
assert hello('Jon') == 'Hello Jon'
git gamble --red
βοΈ Committed
π’ Green phase
Add a simple condition to handle both cases
Alternative text
nano test_hello.py
def hello(arg=None):
if arg:
return f'Hello {arg}'
return 'Hello world'
git gamble --green
βοΈ Committed
π Refactor loop β°
π Refactor phase
It can be simplified
Alternative text
nano test_hello.py
def hello(arg='world'):
return f'Hello {arg}'
git gamble --refactor
βοΈ Committed
Still π Refactor phase : i have something else to refactor βΏ
Better naming
Alternative text
nano test_hello.py
def hello(name='world'):
return f'Hello {name}'
git gamble --refactor
βοΈ Committed
And so on... βΏ
π Repeat until you have tested all the rules, are satisfied and enougth confident