Jump to content

PandaTests - Basic tests manager


SkyzohKey
 Share

Recommended Posts

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();
    }
  });
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...