TDD with Cyber-Dojo

Hello World!

TDD which is the abbreviation of Test Driven Development , is a software development process, that relies on the Code and Test Case. It has a sequence

  • Tester writes a testcase.
  • Developer tries to write a code, that passes the test case
  • Tester tries to write a valid test case, that makes the code to fail.
  • Developer rewrites the code, so that it passes all the test cases
  • Tester includes new testcase that makes the code to fail

This cycle continues until the code passes all the test cases written by the tester. At the end we would get a code with better quality. This is Test Driven Development.

Cyber-Dojo

Cyber-Dojo is a tool that is used to practice TDD. It is a shared learning environment. We can practice TDD in Cyber-Dojo.

Home page of cyber-dojo.org

How to use CyberDojo?

To create a new problem

  1. Click on setup a new practice session.
  2. Select the language in which you code and test framework and click next.
Selecting language (Python) and test framework (py.test)

3. There will be set of available problems. If you want to create a new problem statement, click in verbal in the list and click Ok.

To create our own problem, click on verbal

4. Now a session id is generated. Make a note of that session id and click ok.

Session code is created

5. Now click on Enter a practice session and type the session id and click on start.

Entering a practice session

6. Now an avatar (here the avatar will be animals) is generated for you. Make a note of this avatar. The avatar is used to identify the user. Whenever a user starts a session using a session id, an avatar is generated to the user.

Tiger avatar is generated for the session

The user can resume the practice later by selecting avatar in Continue option.

Continue option avatar selection

There are totally 64 avatars, which means 64 sessions can be created using a session id.

7. Now the session will start in a new tab. It contains,

  • hiker.py (in case of python) — where we write code
  • instructions — where the instruction is given by the instructor.
  • test_hiker.py — where we write test cases
  • output — where we could see the output
  • cyber-dojo.sh — It is a shell script where the logic of TDD is written by the creator.
New Session

It is advisable to rename the hiker.py and test_hiker.py according to the problem that we are working on.

For example, if I am working on a problem called Binary Range, then I will rename hiker.py -> BinaryRange.py and test_hiker.py -> test_BinaryRange.py.

It is also advised that to change the name of methods and classes, so that the program looks meaningful.

Renamed files and methods, classes

8. Now click on the test button.

You could see some number is generated near the avatar and something like a red light.

The number is nothing but the version of the code.

The ‘Red Light’ is nothing but a traffic light, which tells you whether all the test cases are passed, or any test case failed, or compiler error.

There are 3 color codes for traffic lights

  • Green — All test cases passed
  • Red — At least one test case failed
  • Yellow — Compiler Error

On clicking the test button would show the output file. In our case, we have one test case and that one test case failed. So the red light will glow on our timeline.

Result 1 — test failed

Now I have modified the code so that it passes the test case. Now green light glows as all test cases are passed.

Result 2 — test passed

If I have made any compiler error, then yellow light will glow.

Result 3 — Compiler Error

The ‘RED’ and ‘GREEN’ combination continues and the final code will be of better quality.

The Dashboard will show the Red — Green — Yellow pattern for each avatar.

We can also see the differences in each iterations in diff. And we can create a new session from the current version of the problem by clicking Create a practice session from <avatar><iteration> button.

Dashboard

You can see the Binary Range program from this link.

This is an awesome tool to practice TDD. I would like to thank Mr.Jon Jagger, Taunton, UK, the creator of the tool. I would like to extend my thanks Mr. Ashok Bakthavatsalam, Managing Director of KG Information Systems Limited (KGISL), Coimbatore, India, for introducing this tool in Coimbatore and encouraging us to practice in it.

Looking forward for your valuable feedbacks and suggestions.

Thank you!!