@acransac/tester 中文文档教程
tester 是一个简单的测试运行器。 将它添加到项目中:
$ npm install @acransac/tester
并导入它:
const Test = require('@acransac/tester');
然后,使用 Test.makeTest
声明测试并将它们传递给 Test.run
或 Test.runInSequence。 第一个跑步者立即开始所有测试,他们可以按任何顺序完成。 第二个测试一个接一个地执行,按照它们作为参数传递的顺序:
Test.makeTest:: (TestFunction, String) -> 测试
Parameter Type Description testFunction TestFunction A function which executes some logic to be tested, checks the outcome and signals to the runner it is done name String The name of the test. Appears in logs TestFunction:: (() -> (), Boolean -> ()) -> ()
Parameter Type Description finish () -> () A callback provided by the runner to call in the return statement to signal the end of the test check Boolean -> () A callback provided by the runner. The actual test is the expression evaluating to true or false passed as argument to this callback. The test fails if the expression evaluates to false <代码>Test.run:: ([Test], Maybe
) -> () Parameter Type Description tests [Test] The array of tests to run. They all run at once testSuiteName Maybe\ The name of the test suite that appears in logs. Default: Test Suite <代码>Test.runInSequence:: ([Test], Maybe
) -> () Parameter Type Description tests [Test] The array of tests to run. They run one after another in the order of the array testSuiteName Maybe\ The name of the test suite that appears in logs. Default: Test Suite Example: const Test = require('@acransac/tester'); function upperCase(finish, check) { return finish(check("a".toUpperCase() === "A")); } function oddNumber(finish, check) { return finish(check(2 % 2 > 0)); } Test.run([ Test.makeTest(upperCase, "Upper Case"), Test.makeTest(oddNumber, "Odd Number") ], "Elementary Checks");
$ node example.js -------------------- Elementary Checks: Test Odd Number failed! 1 / 2 test(s) passed --------------------
tester is a straightforward test runner. Add it to a project with:
$ npm install @acransac/tester
and import it with:
const Test = require('@acransac/tester');
Then, declare tests with Test.makeTest
and pass them to Test.run
or Test.runInSequence
. The first runner starts all tests at once, and they can complete in any order. The second executes one test after the other, in the order they are passed as arguments:
Test.makeTest:: (TestFunction, String) -> Test
Parameter Type Description testFunction TestFunction A function which executes some logic to be tested, checks the outcome and signals to the runner it is done name String The name of the test. Appears in logs TestFunction:: (() -> (), Boolean -> ()) -> ()
Parameter Type Description finish () -> () A callback provided by the runner to call in the return statement to signal the end of the test check Boolean -> () A callback provided by the runner. The actual test is the expression evaluating to true or false passed as argument to this callback. The test fails if the expression evaluates to false Test.run:: ([Test], Maybe<String>) -> ()
Parameter Type Description tests [Test] The array of tests to run. They all run at once testSuiteName Maybe\ The name of the test suite that appears in logs. Default: Test Suite Test.runInSequence:: ([Test], Maybe<String>) -> ()
Parameter Type Description tests [Test] The array of tests to run. They run one after another in the order of the array testSuiteName Maybe\ The name of the test suite that appears in logs. Default: Test Suite
const Test = require('@acransac/tester');
function upperCase(finish, check) {
return finish(check("a".toUpperCase() === "A"));
}
function oddNumber(finish, check) {
return finish(check(2 % 2 > 0));
}
Test.run([
Test.makeTest(upperCase, "Upper Case"),
Test.makeTest(oddNumber, "Odd Number")
], "Elementary Checks");
$ node example.js
--------------------
Elementary Checks:
Test Odd Number failed!
1 / 2 test(s) passed
--------------------