TestService

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

服务

测试服务是 Roblox 内部使用的服务,用于对其引擎进行分析测试。这使得可以在游戏内直接写复杂的测试。

麦克风

在测试服务内执行的脚本(通过 TestService:Run())可以访问直接调用测试服务下的函数的特殊 macro。麦克风本质上是用来替换大块代码,每次调用它们时不需要重写的。

RBX_检查

这个 macro 使用调用 TestService:Check() 函数进行测试。


<th>测试条件</th>
</tr>
<tr>
<td>RBX_检查(cond)</td>
<td>条件 == 真实</td>
</tr>
<tr>
<td>RBX_检查_消息(cond, failMsg)</td>
<td>条件 == 真实</td>
</tr>
<tr>
<td>RBX_检查_投掷(代码)</td>
<td>pcall(函数() 结束) == 错误</td>
</tr>
<tr>
<td>RBX_检查_不投掷(代码)</td>
<td>pcall(函数() 结束) == 真</td>
</tr>
<tr>
<td>RBX_检查_等于(a,b)</td>
<td>a == b</td>
</tr>
<tr>
<td>RBX_检查_NE(a,b)</td>
<td>a ~= b</td>
</tr>
<tr>
<td>RBX_检查_GE(a,b)</td>
<td>a >= b</td>
</tr>
<tr>
<td>RBX_检查_le(a,b)</td>
<td>a <= b</td>
</tr>
<tr>
<td>RBX_检查_GT(a,b)</td>
<td>a > b</td>
</tr>
<tr>
<td>RBX_检查_LT(a,b)</td>
<td>a < b</td>
</tr>
微观

RBX_需求

这个 macro 使用调用 TestService:Require() 函数进行测试。


<th>测试条件</th>
</tr>
<tr>
<td>RBX_REQUIRE(条件)</td>
<td>条件 == 真实</td>
</tr>
<tr>
<td>RBX_REQUIRE_MESSAGE(条件, 失败Msg)</td>
<td>条件 == 真实</td>
</tr>
<tr>
<td>RBX_REQUIRE_THROW(代码)</td>
<td>pcall(函数() 结束) == 错误</td>
</tr>
<tr>
<td>RBX_REQUIRE_NO_THROW(代码)</td>
<td>pcall(函数() 结束) == 真</td>
</tr>
<tr>
<td>RBX_REQUIRE_EQUAL(a,b)</td>
<td>a == b</td>
</tr>
<tr>
<td>RBX_REQUIRE_NE(a,b)</td>
<td>a ~= b</td>
</tr>
<tr>
<td>RBX_REQUIRE_GE(a,b)</td>
<td>a >= b</td>
</tr>
<tr>
<td>RBX_REQUIRE_LE(a,b)</td>
<td>a <= b</td>
</tr>
<tr>
<td>RBX_REQUIRE_GT(a,b)</td>
<td>a > b</td>
</tr>
<tr>
<td>RBX_REQUIRE_LT(a,b)</td>
<td>a < b</td>
</tr>
微观

RBX_警告

这个 macro 使用调用 TestService:Warn() 函数进行测试。


<th>测试条件</th>
</tr>
<tr>
<td>RBX_WARN(条件)</td>
<td>条件 == 真实</td>
</tr>
<tr>
<td>RBX_WARN_MESSAGE(cond, 失败Msg)</td>
<td>条件 == 真实</td>
</tr>
<tr>
<td>RBX_WARN_THROW(代码)</td>
<td>pcall(函数() 结束) == 错误</td>
</tr>
<tr>
<td>RBX_WARN_NO_THROW(代码)</td>
<td>pcall(函数() 结束) == 真</td>
</tr>
<tr>
<td>RBX_WARN_EQUAL(a,b)</td>
<td>a == b</td>
</tr>
<tr>
<td>RBX_WARN_NE(a,b)</td>
<td>a ~= b</td>
</tr>
<tr>
<td>RBX_WARN_GE(a,b)</td>
<td>a >= b</td>
</tr>
<tr>
<td>RBX_WARN_LE(a,b)</td>
<td>a <= b</td>
</tr>
<tr>
<td>RBX_WARN_GT(a,b)</td>
<td>a > b</td>
</tr>
<tr>
<td>RBX_WARN_LT(a,b)</td>
<td>a < b</td>
</tr>
微观

额外的 Mac 命令


<th>描述</th>
</tr>
<tr>
<td>RBX_ERROR(msg)</td>
<td>直接调用 <code>Class.TestService:Error()</code> 函数。</td>
</tr>
<tr>
<td>RBX_失败(msg)</td>
<td>直接调用 <code>Class.TestService:Fail()</code> 函数。</td>
</tr>
<tr>
<td>RBX_MESSAGE(msg)</td>
<td>直接调用 <code>Class.TestService:Message()</code> 函数。</td>
</tr>
微观

概要

属性

方法

活动

属性

AutoRuns

读取并联

如果设置为真,游戏将在 TestService 的 TestService:Run() 方法调用时开始运行。

Description

读取并联

执行的测试的描述。

ErrorCount

只读
未复制
读取并联

测量在测试会话中记录了多少错误。

ExecuteWithStudioRun

读取并联

当设置为真时,TestService 将在 Roblox Studio 中使用 运行 行动时执行。

注意:

  • 如果 TestService.NumberOfPlayers 属性设置为 0 以上的值,运行游戏将打开 NumberOfPlayers + 1 工作室窗口,其中一个窗口是服务器,其余的是连接到该服务器的玩家。
  • 尝试将此值保持在合理范围内(最多 8 名玩家),否则您的计算机处理器将过载。

IsPhysicsEnvironmentalThrottled

读取并联

设置物理环境在运行此测试时是否应被限制。

IsSleepAllowed

读取并联

设置是否允许物理对象在测试模拟运行时睡眠。

NumberOfPlayers

读取并联

如果有的话,在这次测试中期望的玩家数量。

SimulateSecondsLag

读取并联

设置玩家在测试会话期间遇到的额外延迟数量。

TestCount

只读
未复制
读取并联

测量测试会话中记录了多少测试呼叫。

ThrottlePhysicsToRealtime

读取并联

Timeout

读取并联

测试可以运行的最大时间。

WarnCount

只读
未复制
读取并联

测量在测试会话中记录了多少警告呼叫。

方法

Check

()

如果条件为真的,会打印“检查通过:”,然后跟随描述到输出,以蓝色文本显示。否则,打印“检查失败:”,再次跟随描述,但红色文本。

参数

condition: boolean
默认值:""
description: string
默认值:""
source: Instance
默认值:"nil"
line: number
默认值:0

返回

()

代码示例

This code would print Check failed: example to the output, in red text.

TestService:Check

local TestService = game:GetService("TestService")
TestService:Check(false, "example")

Checkpoint

()

打印“测试检查点:”,然后跟随文本,到输出,蓝色文本。

参数

text: string
默认值:""
source: Instance
默认值:"nil"
line: number
默认值:0

返回

()

代码示例

This code would print Test checkpoint: example to the output, in blue text.

TestService:Checkpoint

local TestService = game:GetService("TestService")
TestService:Checkpoint("example")

Done

()

向输出打印 测试完成,蓝色文本。


返回

()

代码示例

This code would print Testing Done to the output, in blue text.

TestService:Done

local TestService = game:GetService("TestService")
TestService:Done()

Error

()

向输出打印红色消息,前缀为 TestService: .

参数

description: string
默认值:""
source: Instance
默认值:"nil"
line: number
默认值:0

返回

()

代码示例

This will print TestService: "This is an error" to the output.

TestService:Error

local TestService = game:GetService("TestService")
TestService:Error("this is an error")

Fail

()

指示 TestService 奔跑行中的致命错误。如果在测试服务内运行的脚本中调用此操作,将启动在错误被调用的线上的断点。

参数

description: string
默认值:""
source: Instance
默认值:"nil"
line: number
默认值:0

返回

()

Message

()

打印 测试消息 , 然后以 文本 形式将其输出到蓝色文本。

参数

text: string
默认值:""
source: Instance
默认值:"nil"
line: number
默认值:0

返回

()

代码示例

This code would print Test message: example to the output, in blue text.

TestService:Message

local TestService = game:GetService("TestService")
TestService:Message("example")

Require

()

如果 condition 是真的,将 Require passed: 印刷到蓝色文本的输出,然后跟随 description 打印。否则,打印 Require failed. Test ended: , 随后跟随 description , 到红色文本的输出。

参数

condition: boolean
默认值:""
description: string
默认值:""
source: Instance
默认值:"nil"
line: number
默认值:0

返回

()

代码示例

This code would print Require passed: example to the output, in blue text.

TestService:Require

local TestService = game:GetService("TestService")
TestService:Require(false, "example")

ScopeTime


返回

Warn

()

如果条件为真,将打印警告传递:,随后跟随描述,以蓝色文本输出。否则,将 警告: 印刷到输出,在黄色文本后,跟随 描述:

参数

condition: boolean
默认值:""
description: string
默认值:""
source: Instance
默认值:"nil"
line: number
默认值:0

返回

()

代码示例

This code would print "Warning: this action is invalid" to the output, in yellow text.

TestService:Warn

local TestService = game:GetService("TestService")
TestService:Warn(false, "this action is invalid")

isFeatureEnabled

参数

name: string
默认值:""

返回

Run

()
暂停
插件安全性

运行与 TestService 关联的脚本。


返回

()

活动

ServerCollectConditionalResult

当服务器应收集条件测试结果时,发射。

参数

condition: boolean
text: string
script: Instance
line: number

ServerCollectResult

当服务器应收集测试结果时发射。

参数

text: string
script: Instance
line: number