ThanosS

v2
PandaTests - Basic tests manager

2 posts in this topic

Hey,

Still working on my Bomberman-clone, today I was writing the Grid component and was looking for a way to check if everything was working properly. Nothing better than tests to check if everything is correct, so I wrote a quick but useful plugin to do... tests :)

PandaTests is a plugin for Panda.js that permits to do assertions the right way. To learn more about this plugin, read the following samples.

You can download it via GitHub since I finally created a repository for my plugins: PandaTests on GitHub

687474703a2f2f692e696d6775722e636f6d2f54

Installation

In order to install PandaTests, simply copy this file into your <project_root>/src/plugins folder. That's all ! You'll then have to require it whenever you want to use it in your code. (see the samples)

Samples

Basic usage

File main.js:

game.module('game.main')
.require('plugins.tests')
.body(function () {
  game.createScene('Main', {
    init: function () {
      // We first instanciate a Test object.
      var test = new game.Test();

      // Then we proceed our tests.
      test.assert(true == true, 'true equals true'); // Test pass
      test.assert(true == false, 'true equals false'); // Test fails
      test.assert(0 == false, '0 equals false'); // Test pass
      test.assert('false' == false, '"false" equals false'); // Test fails

      // Now we can ask for tests results.
      test.showResults();
      /**
      * -- Tests results --
      * - Passed tests: 2 (50%)
      * - Failed tests: 2 (50%)
      * - Total  tests: 4
      * -- Tests results --
      **/

      // We can also reset tests results.
      test.resetCounters();
    }
  });
});

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.