1. 程式人生 > >【指令碼語言】【】RINGO JS-模組 test

【指令碼語言】【】RINGO JS-模組 test

模組 test

符合 CommonJS Unit 單元測試規範的測試執行器。 它管理單元測試的執行並處理測試結果。 跑步者將失敗的總數報告為退出狀態碼。

跑步者將模組視為測試用例。 測試用例定義了燈具執行多個測試。 測試用例可以提供可選的setUp() 和 tearDown() 函式來初始化和銷燬燈具。 測試執行人員將在每次測試之前/之後執行這些方法。 測試函式必須以名稱中的測試字首開頭,否則跑步者會跳過它們。

下面的示例測試用例 testDatabase.js 在用 ringo testDatabase.js 執行時啟動一個新的測試執行器

Example

// testDatabase.js
exports.setUp = function() { ... open db connection ... }
exports.tearDown = function() { ... close db connection ... }

// Test functions start with the prefix 'test'
exports.testCreateTable = function() { ... }
exports.testInsertData = function() { ... }
exports.testTransactions = function() { ... }
exports.testDeleteTable = function() { ... }

if (require.main === module) {
  // Get a runner and run on the current module
  require("test").run(exports);
}

See

assert 模組是一個用於編寫單元測試的斷言庫。

Functions


getStackTrace (trace)

建立一個堆疊跟蹤並解析它以便顯示。

Parameters

java.lang.StackTraceElement trace

The trace to parse. If not given a stacktrace will be generated

Returns

String

The parsed stack trace


getType (obj)

返回作為引數傳遞的物件的型別。

Parameters

Object obj  

Returns

String

The type of the object passed as argument


jsDump (value, lvl)

將作為引數傳遞的值轉換為格式良好並帶有縮排的字串。

Parameters

Object value

The value to convert into a string

Number lvl

Optional indentation level (defaults to zero)

Returns

String

The string representation of the object passed as argument


run (scope, name, writer)

主要的跑步者方法。可以用一個,兩個或三個引數呼叫此方法:run(scope)run(scope, nameOfTest)run(scope, writer) 或 run(scope, nameOfTest, writer)

Parameters

String|Object scope

Either the path to a module containing unit tests to execute, or an object containing the exported test methods or nested scopes.

String name

Optional name of a test method to execute

Object writer

Optional writer to use for displaying the test results. Defaults to TermWriter.