Skip to main content

Gamify TDD

I like it when things that would not normally be associated with games add concepts from games as a way to incentives you to accomplish things. Why simply go for a run if you can have an app that will track you and give you a gold star if you do better than you did the last time? Why go to the coffee shop that only gives you coffee if the other one will give you points that you can redeem for free drinks eventually?

I was recently introduced to CodeSchool, an online training system similar to PluralSight, it has video courses and challenges you can take to prove that you retained what the video taught. CodeSchool also adds badges and tracks to your learning, so as you complete a video and its challenges you get a badge. Complete a collection of courses within a specific discipline and you become a master of that discipline.

Some of these incentives are not tangible and really don't mean much in the real world, but they tend to work for me. If I start working towards a large goal and I have little pieces of motivation to help me along, I am more likely going to want to complete the goal and collect all the trinkets that come along with it than if the end is way off in the future. I am also more likely to complete the task sooner because I can get a sense of completion much faster by reaching a smaller goal/achievement/badge/star and I will continue to be motivated to reach that next smaller piece.

TDD has some of these incentives built in already. You should be making small breaking changes that you can then quickly fix. After I fix a small issue and see my tests pass, I feel a little surge of success that I carry with me into the next change that needs to be made. By breaking changes down into small chunks that you can solve quickly you are also focusing on the little thing in front of you that you can do, rather than on the overall, larger problem.

This is again an area that I love NCrunch, NCrunch is constantly testing my project and will tell me when a test is failing, and also when a test passes. Having this immediate feedback really increases the feeling of success when I get a test to pass. NCrunch goes a step further on the path of making TDD act like a game though. It adds to the sidebar of the code window indicators that let me know if the code I am looking at is covered by a test, passing that test, failing that test, and has possible efficiency issues. If I open an existing class and don't see a bunch of colored dots along the side, I know that this class is not covered under any tests. If I see a bunch of Red dots on the side, I know that there are failing tests that I need to fix. As I work through changes I can see my progress immediately, in the window I am coding in without needing to switch over and run my tests.

So NCrunch provides me with a level of gamification above just testing by providing feedback in the code window, attached to the executing code itself. What I would like to see next would be to increase the incentives for more coding. Perhaps some achievements could be added that tie into your tests and code. If I create 10 tests and get them to pass I get a badge. If I cover 100 lines of code with passing tests I get a star. Maybe it could be reputation points like StackOverflow. Design a fully tested class and you get 10 points. Find a way to refactor out 10 lines of code and you get 5 points.

These ideas are based on the details of the code, I think there is also an opportunity for gamifying productivity. If you work in the same class for 30 minutes, you get a medal. If you complete 4 uninterrupted pomodoro sessions within a day, you get a "Way to go" message you can post to Twitter or Facebook.

How about a way to unlock new features as you learn? Gating progress in a game until the user has shown the ability to complete certain tasks is a staple of games. If you are bringing on a new person to the team, they may not have knowledge of the product or the procedures that your team follows. You are probably going to limit what areas they touch in the system until they get up to speed. You are likely not going to throw them into the most complex part of the system on day 1. So I would assume most places have a gating system in place already, just probably not in a formal, defined way. Why not find a way to turn that into a game?

Lets say that your project is very well tested and you want to get the new developer up to speed, but you don't want to give them access to everything immediately. How about giving them the project without the tests. Have them look at a simple, small section of the system, and have them write tests until they have covered that section with passing tests. As they complete a section, move them on to a more complicated part of the system doing the same thing. That new dev would get a good understanding of the system as they worked through creating the new tests. Your team may also find some issues in the code as the new member find spots that they have difficulty with. Or you may find areas that the new member needs assistance with in getting up to the speed with the rest of the team. Turning the on-boarding process into a game will likely engage that new employee better than having them stare at their screen for a few weeks before you let them touch code.

What other ideas would be good to gamify coding and testing? Are there any tools that do any of the ideas listed above that I don't know about?

Comments

Popular posts from this blog

Converting a Large AngularJS Application to TypeScript Part 2

In part 1 I was able to take an Angular controller written in JavaScript and convert it to a TypeScript file while doing very little to change the code. In this post I am going to explore transitioning that same controller to actually use the features provided in TypeScript. This is how I left off my controller:
declare var angular: any; (function () { 'use strict'; var controller: any = function($scope){ ... } angular .module('app') .controller('controller', controller); controller.$inject = ["$scope"]; })();
While performing the translation from JavaScript to TypeScript, I would make sure at every step that the functionality I expected still worked, so if anything I did broke the system I would change it back and try again with another approach. Also if something seemed like it worked too easily, I would break it on purpose to make sure I wasn't getting a false result through browser caching a previously working fil…

Converting a Large AngularJS Application to TypeScript Part 1

I work on a project that uses AngularJS heavily. Recently we wondered if using a preprocesser like CoffeeScript or TypeScript for our JavaScript would be beneficial. If our team is going to switch languages, we would need to be able to convert existing code over without much pain and we would have to find enough value in switching that it would be worth the conversion.

I had read an article that stated that because TypeScript is a SuperSet of JavaScript, you could convert a plain JavaScript file to TypeScript by changing the extension to .ts and not much else would need to change. I wanted to test out this claim, so I took a file that I was familiar with, an Angular Controller, and tried to convert it to TypeScript to see how much effort it would take and then try to figure out where we would benefit from using TypeScript.

This is what the controller JavaScript file looked like to start out with:
(function () { 'use strict'; angular .module('app') …