@acransac/tester 中文文档教程

发布于 4年前 浏览 18 项目主页 更新于 3年前

tester 是一个简单的测试运行器。 将它添加到项目中:

    $ npm install @acransac/tester

并导入它:

    const Test = require('@acransac/tester');

然后,使用 Test.makeTest 声明测试并将它们传递给 Test.runTest.runInSequence。 第一个跑步者立即开始所有测试,他们可以按任何顺序完成。 第二个测试一个接一个地执行,按照它们作为参数传递的顺序:

  • Test.makeTest:: (TestFunction, String) -> 测试

    ParameterTypeDescription
    testFunctionTestFunctionA function which executes some logic to be tested, checks the outcome and signals to the runner it is done
    nameStringThe name of the test. Appears in logs

  • TestFunction:: (() -> (), Boolean -> ()) -> ()

    ParameterTypeDescription
    finish() -> ()A callback provided by the runner to call in the return statement to signal the end of the test
    checkBoolean -> ()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) -> ()

    ParameterTypeDescription
    tests[Test]The array of tests to run. They all run at once
    testSuiteNameMaybe\The name of the test suite that appears in logs. Default: Test Suite

  • <代码>Test.runInSequence:: ([Test], Maybe) -> ()

    ParameterTypeDescription
    tests[Test]The array of tests to run. They run one after another in the order of the array
    testSuiteNameMaybe\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

    ParameterTypeDescription
    testFunctionTestFunctionA function which executes some logic to be tested, checks the outcome and signals to the runner it is done
    nameStringThe name of the test. Appears in logs

  • TestFunction:: (() -> (), Boolean -> ()) -> ()

    ParameterTypeDescription
    finish() -> ()A callback provided by the runner to call in the return statement to signal the end of the test
    checkBoolean -> ()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>) -> ()

    ParameterTypeDescription
    tests[Test]The array of tests to run. They all run at once
    testSuiteNameMaybe\The name of the test suite that appears in logs. Default: Test Suite

  • Test.runInSequence:: ([Test], Maybe<String>) -> ()

    ParameterTypeDescription
    tests[Test]The array of tests to run. They run one after another in the order of the array
    testSuiteNameMaybe\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
    --------------------
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文