Acceptance Tests, My Hero!

I believe strongly in behavior driven development (BDD) and acceptance testing. My standard workflow looks something like:

  1. write high-level acceptance test
  2. write unit test for a component
  3. make unit test pass
  4. go to 2 until acceptance test passes

This pattern has served me very well in the professional realm. However, when I sit down to play with personal game development project, gamebox, acceptance testing and BDD tend to go out the window.

I go into “let’s get a dragon in the game” mode. With two kids, a wife, and a home to maintain, my time is always fleeting. Naively optimizing for short-term results, I tend to write unit tests only for interesting code and rarely ever write acceptance tests.

As gamebox grew in complexity, I hit a point where a large refactor was required. I started using David Crosby’s conject gem. Conject takes over all of my dependency management and object construction, essentially touching every piece of the framework. I realized that in the current system, the only way I’d know that I had hooked up all the pieces correctly was to slowly update all the games that I had built using gamebox and see if they work. That approach sounded like a fail-train waiting to leave the station.

I finally sat down in the working system and wrote an acceptance test. The first test was the hardest. After writing a few helpers and moving things around I had a test that proved that a game object could be created, added, drawn, and receive keyboard input. The great thing about the testing harness that I had to write is that games built with gamebox can use them to acceptance test their games, as well. Double win!


  it 'creates an actor from within stage with the correct behaviors and updates' do
    game.stage do |stage|
      create_actor :mc_bane, x: 250, y: 400
    end
    see_actor_attrs :mc_bane, bullets: 50

    update 10
    see_image_not_drawn mc_bane_png

    draw
    see_image_drawn mc_bane_png

    see_actor_attrs :mc_bane, bullets: 40
    game.should have_actor(:mc_bane)

    release_key KbD

    # should have removed himself
    game.should_not have_actor(:mc_bane)

  end

Save yourself the headache. Start with the acceptance tests and drive from there. They improve your design and let you know when you’re done. I use them every day in the office, and now I play the home version, too. They can be real life savers.