Game development using TDD – Part 1

How about a game?

How about developing a game using TDD?

As a TDD advokator, I’m a firm believer that TDD can help to boost productivity and quality in any domain. but, when I try to find examples of using TDD for game development I stopped short. So, I thought I could create one.

In this series we will develop the infamous snake video game using JavaScript, and we’ll do it using TDD, that’s right, test first.

So let’s start from an empty working test. We’ll be using Jasmine as our testing framework.

First we want to have a test that runs, our first test will do nothing, literally

describe("Nothing", function() {
  it("does nothing", function() {
    expect("A").toEqual("A");
  });
});

Now let’s configure Jasmine to run our test, your Jasmine HTML should like this:

<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.5.2</title>

  	<link rel="shortcut icon" type="image/png" href="jasmine-2.5.2/jasmine_favicon.png">
  	<link rel="stylesheet" href="jasmine-2.5.2/jasmine.css">

  <script src="jasmine-2.5.2/jasmine.js"></script>
  <script src="jasmine-2.5.2/jasmine-html.js"></script>
  <script src="jasmine-2.5.2/boot.js"></script>

  <!-- include source files here... -->
  <script src="src/snake.js"></script>
  <!-- include spec files here... -->
  <script src="spec/snake_spec.js"></script>
</head>
<body>
</body>
</html>

That’s it! we have a working empty test and we’re ready to go!

screen-shot-2016-11-29-at-12-08-35

In the next part we will start with our first “real” test

Leave a comment