MultiRogue Dev Logs – Mocha Tests

I’ve been spending the last two days building up the test framework to make tests as legible and easy to make as possible. From experience, this is the only way automated tests can even make their way into a project… if they’re dead simple.

I’m using a fluent interface and simple action verbs to send commands to the client. Here’s an example of one of my tests:

describe('client picking up and dropping stick', function() {
    var client;
    beforeEach(function(){
        client = Simulator.serverBoots().clientConnects();
    });
    it('should see the stick on the ground before', function() {
        should(client.getTileTokenAt(46, 27)).be.eql('/');
    });
    it('should not be holding stick at first', function() {
        should(client.isHoldingItem('Wooden Stick')).be.false();
        should(client.hasInLog('You pick up the Wooden Stick.')).be.false();
    });
    it('should be holding stick after picking it up', function() {
        client.moveLeft().moveLeft().moveDown().moveLeft()
            .picksUpOffFloor();
        should(client.isHoldingItem('Wooden Stick')).be.true();
        should(client.hasInLog('You pick up the Wooden Stick.')).be.true();
    });
    it('should not see the stick on the ground after picking it up', function() {
        client.moveLeft().moveLeft().moveDown().moveLeft()
            .picksUpOffFloor().moveLeft();
        should(client.getTileTokenAt(46, 27)).not.be.eql('/');
    });
    //... . .. ..

Next I’m going to be making a couple of tests suits to represent all the features that my game currently has. Once that’s done, I’ll be able to refactor and add new features without being afraid of causing regression bugs.


No comments yet.

Leave a Reply