aardio 文档

util.testRunner 库模块帮助文档

util 成员列表 #

util.testRunner #

自动化测试运行器。
无控制台输出、无 UI 阻塞,report() 返回结构化 table 报告。
util.testRunner 专为 AI Agent 而设计(已被用于 aardio autos )。
如果需要用户界面请改用 console.test console.expect 等控制台测试函数

创建自动化测试运行器实例。

util.testRunner() #

返回对象:utilTestRunnerObject

util.testRunner(options) #

options 可指定包含 suiteName,maxDepth,maxItems,maxStringBytes,maxBufferBytes 的选项表。

util.testRunner(suiteName,options) #

suiteName 可指定套件名字符串。  
options 可指定包含 maxDepth,maxItems,maxStringBytes,maxBufferBytes 的选项表。

utilTestRunnerObject 成员列表 #

utilTestRunnerObject.assert(condition,testName,detail) #

断言条件,失败时记录结果并抛出错误中断执行。
参数 @testName 指定断言名称。
可选参数 @detail 指定测试失败时的详细描述。

utilTestRunnerObject.contains #

测试字符串、表对象、数组是否包含指定值

utilTestRunnerObject.contains(container,expected,testName) #

参数 @container 指定字符串或表(对象或数组)。
参数 expected 指定要查找的值。
参数 @testName 指定测试项名称。

utilTestRunnerObject.expect #

期望值测试

utilTestRunnerObject.expect(actual,expected,testName) #

对比实际值 @actual 与期望值 @expected,全等或 JSON 序列化相等即通过。
参数 @testName 指定测试项名称。

utilTestRunnerObject.expectNear #

数值近似比较,适合浮点数测试。

utilTestRunnerObject.expectNear(actual,expected,testName,tolerance) #

对比实际数值 @actual 与期望数值 @expected。
在给定的容差(@tolerance)范围内是否相等。
可选参数 @tolerance 指定浮点容差,默认值 0.000001。

utilTestRunnerObject.fail(testName,detail) #

显式记录失败。
参数 @testName 指定测试项名称。
参数 @detail 指定详细描述,不可省略。

utilTestRunnerObject.log(value,message) #

记录观察值用于调试,不影响通过/失败统计。

utilTestRunnerObject.match(str,pattern,testName) #

使用 aardio 模式匹配测试字符串。

utilTestRunnerObject.notThrows(fn,testName) #

期望函数不抛出错误。。

utilTestRunnerObject.report() #

返回包含 suiteName,total,passed,failed,success,durationMs,results 的结构化 table 报告。

utilTestRunnerObject.reset() #

清空当前测试统计数据与记录,并重置计时器。

utilTestRunnerObject.summary() #

report() 的别名。

utilTestRunnerObject.test #

条件测试

utilTestRunnerObject.test(condition,testName,detail) #

验证并记录参数 @condition 指定的布尔值条件测试项,返回是否通过。
参数 @testName 指定测试项名称。
可选参数 @detail 指定测试失败时的详细描述。

utilTestRunnerObject.throws(fn,testName,expectedPattern) #

期望函数抛出错误,可用模式匹配错误文本。

Markdown 格式