Giter Site home page Giter Site logo

simpleunittest's Introduction

SimpleUnitTest

Simple unit test framework for not node based javascript modules.

Usage

Install the package with npm:

npm install -g sutest

Write your test script file:

module.exports = function (unitTest) {

	unitTest.AddTest ('AdditionTest', function (test) {
		test.Assert (2 + 3 == 5);
	});
	
};

Run the test from command line:

sutest mytestfile.js

Create suites

You can create test suites, and add tests to suites:

module.exports = function (unitTest) {

	var opTestSuite = unitTest.AddTestSuite ('OperationsTest');
	
	opTestSuite.AddTest ('AdditionTest', function (test) {
		test.Assert (2 + 3 == 5);
	});
	
	opTestSuite.AddTest ('SubtractionTest', function (test) {
		test.Assert (2 - 3 == -1);
	});
	
};

Include modules

You can add not node based modules, and use them in your tests.

For example, create a module with this content:

function Addition (a, b)
{
	return a + b;
}

function Subtraction (a, b)
{
	return a - b;
}

Now you can add this module to your test:

module.exports = function (unitTest) {

	unitTest.AddSourceFile ('./operationsmodule.js');
	
	var opTestSuiteLib = unitTest.AddTestSuite ('OperationsTestFromLib');
	
	opTestSuiteLib.AddTest ('AdditionTest', function (test) {
		test.Assert (Addition (2, 3) == 5);
	});
	
	opTestSuiteLib.AddTest ('SubtractionTest', function (test) {
		test.Assert (Subtraction (2, 3) == -1);
	});
	
};

Create multiple test files

You can create multiple test files, and call them from a main test file:

module.exports = function (unitTest)
{

	unitTest.AddTestFile ('./additiontest.js');
	unitTest.AddTestFile ('./subtractiontest.js');

};

Usage as library

Install the package locally:

npm install sutest

Create your standalone test file:

var path = require ('path');
var dirName = path.dirname (require.main.filename);

var sutest = require ('sutest');
var unitTest = new sutest.UnitTest (dirName, process.argv);

var opTestSuite = unitTest.AddTestSuite ('OperationsTest');
opTestSuite.AddTest ('AdditionTest', function (test) {
	test.Assert (2 + 3 == 5);
});

opTestSuite.AddTest ('SubtractionTest', function (test) {
	test.Assert (2 - 3 == -1);
});

unitTest.Run ();

Run the test from command line:

node mytestfile.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.