Module basic module

Module test

Test suite module to define management test suite

Instructions:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
var test = require('test'); test.setup(); describe('test', () => { before(() => { // setup before the whole test }); beforeEach(() => { // setup before each test }); after(() => { // cleanup after the whole test }); afterEach(() => { // cleanup after each test }); it('case', () => { assert.ok(true); }); // ignored test case xit('case', () => { assert.ok(true); }); // ignored test case it.skip('case', () => { assert.ok(true); }); // only test case oit('case', () => { assert.ok(true); }); // only test case it.only('case', () => { assert.ok(true); }); }); // async function test describe('test async', () => { it('pass case', async () => { assert.ok(true); }); it('error case', async () => { throw new Error('some thing wrong!'); }); }); // callback function test // cannot use callback mode in jsc describe('test callback', () => { it('pass case', done => { setTimeout(() => { assert.ok(true); done(); }, 0); }); it('error case', done => { setTimeout(() => { done(new Error('some thing wrong!')); }, 0); }); }); process.exit(-test.run(console.DEBUG));

Object

assert

Assert the test module, if the test value is false, an error will be reported, and the error behavior can be set to continue running or throw an error

1
assert test.assert;

Static function

describe

Define a test module, can be nested definition

1 2
static test.describe(String name, Function block);

Call parameters:

  • name : String, defines the module name
  • block : Function, module initialization code

xdescribe

The module definition to pause the test, test.setup can use describe.skip to call after test.setup

1 2
static test.xdescribe(String name, Function block);

Call parameters:

  • name : String, defines the module name
  • block : Function, module initialization code

odescribe

Module definition for independent test, test.setup can use describe.only to call after test.setup

1 2
static test.odescribe(String name, Function block);

Call parameters:

  • name : String, defines the module name
  • block : Function, module initialization code

it

Define a test project

1 2
static test.it(String name, Function block);

Call parameters:

  • name : String, defines the project name
  • block : Function, test content

xit

The project definition of the pause test, after test.setup , it can be called by it.skip

1 2
static test.xit(String name, Function block);

Call parameters:

  • name : String, defines the project name
  • block : Function, test content

oit

Project definition for independent test, can be called with test.setup after test.setup

1 2
static test.oit(String name, Function block);

Call parameters:

  • name : String, defines the project name
  • block : Function, test content

before

Define the current test module entry event

1
static test.before(Function func);

Call parameters:

  • func : Function, event function

after

Define the exit event of the current test module

1
static test.after(Function func);

Call parameters:

  • func : Function, event function

beforeEach

Define the test item entry event of the current test module

1
static test.beforeEach(Function func);

Call parameters:

  • func : Function, event function

afterEach

Define the exit event of the current test module test project

1
static test.afterEach(Function func);

Call parameters:

  • func : Function, event function

run

Start to execute the defined test module

1
static Integer test.run(Integer loglevel = console.ERROR);

Call parameters:

  • loglevel : Integer, specify the log output level during the test. In the case of ERROR, the project error information will be displayed after the report. When it is lower than ERROR, the output information will be displayed at any time. When it is higher than ERROR, only the report will be displayed.

Return result:

  • Integer , returns the statistical result of the test case, if correct, it returns 0, if it is wrong, it returns the wrong number

setup

Initialize the test environment of the current script, copy the test module method to the current script global variable

1
static test.setup();

Static properties

slow

Integer, set and query the slow test warning threshold, in ms, the default is 75

1
static Integer test.slow;