1

Cocos2dx, Test Driven Development and Me

Yes it begins, I’ve restarted my blog, and I’ve started developing a game idea. There I’ve said it and announced it to the world!

I’ve written native iOS, written bits of java and bits of C,C++ over the years for different projects and for this one I decided to try out a few frameworks. My preference was for something that would be cross platform so I didn’t have to fully program in java for Android, and fully do iOS etc. After a brief bit of time playing with lua systems like corona, gideros and moai I found them either closed or restrictive and not as hackable as I’d like.

I’d read the books about cocos2d-iphone and played with it for a while and then I read the Cocos2dx book and felt back at home. I wrote my first C++ code in 1987! and it just felt like putting back on a favourite T-shirt.

cocos2dx.com

Cocos2d Logo

Now I’ve had quite a bit of exposure to different development methodolgies over the years and the current Agile/Scrum/Kaban/Extreme/MVP/TDD/BDD stuff all has reflections of things we did back in the 1990’s at JP Morgan Chase. I didn’t know this but according to my old friend and colleague Steve Traugott, who came over to the UK and stopped by for a visit last month, some of our work back then inspired isconf, chef and puppet system building tools.! Oh and we did quite a few projects using Agile methods – even though we didn’t have a name for them – whilst all the time reporting back  to the waterfall project managers so they could tick their boxes. Oh how things come round eh!

Anyway back to this game project. So I set myself some constraints.

1. I’d use Cocos2dx version 2.2.2 (not the beta 3 which shuffled so many things around that tutorials were a it thin on the ground.)

2. I’d develop for iPhone 4/5 and Android devices.

3. I’d develop using vim to begin with and avoid the big IDE’s like Xcode and Eclipse (So I could still do the initial development on my old laptop – which I’ll detail in another post!)

4. I’d try out TDD using google_test and google_mocks. I did try out cppunit but couldn’t get it to compile right)

5. I’d use only open source or free editors for the graphics and sound effects.n

6. I’d allow myself to use Reason 6 for my background music as I’ve properly owned it for years and I’m afraid the free stuff is still not quite as rounded.

The first step was to get my environment set up so downloading the source code, setting up a git repo on bitbucket (so I can keep it private for the moment so my really bad code stays hidden!)

Then the next step was to get the TDD cycle setup. This was a bit of a pest as I don’t think many other people have tried it with Cocos2d or game development at all and to be honest its quite difficult to get my head around although its getting easier.

I used the cocos2dx python project generation script and then copied over the proj.linux directory contents to unit.test.linux. A few nights of hacking away at the Makefile finally got my first test running.

So here’s the makefile as it is for the moment.

Now running make run from within the unit.test.linux directory will compile the app, run up an instance and run the test classes I’ve defined.

Now before you look and comment on how I could write my makefile better, this is a first pass.
I know I could do easier includes etc but it will do for now whilst I’m just getting started.

Of course if I had enough RAM in this old war horse, I’d run up eclipse and use the built in test runner stuff.

So next how to write tests. Well unit testing is all about isolating each item and TDD is about writing the tests first. Write test->RED->Write code->RED->Fix Code->Green->Refactor code->RED->FIx refactor->GREEN rinse and repeat.

So onward with the tests and creation of the program. Next time its CCPhysicsSprites.

 

Spencer Westwood
 

Author, musician, developer and generally a bit of a self confessed computer geek.