TestService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

服務

測試服務是 Roblox 內部使用的服務,用於在其引擎上執行分析測試。這讓您可以在遊戲內寫出複雜的測試。

微型指令

在測試服務內執行的腳本(通過 TestService:Run() )可以使用直接呼叫測試服務下的函數的特殊 macro。微型指令本質上是用來取代大型代碼塊,每次呼叫它們時不需要重寫。

RBX_檢查

這個 macro 使用 TestService:Check() 函數進行測試。


<th>測試條件</th>
</tr>
<tr>
<td>RBX_檢查(cond)</td>
<td>cond == 真實</td>
</tr>
<tr>
<td>RBX_CHECK_MESSAGE(條件,失敗訊息)</td>
<td>cond == 真實</td>
</tr>
<tr>
<td>RBX_CHECK_THROW(代碼)</td>
<td>pcall(function() 代碼結束) == 否</td>
</tr>
<tr>
<td>RBX_CHECK_NO_THROW(代碼)</td>
<td>pcall(function() 代碼結束) == 真</td>
</tr>
<tr>
<td>RBX_CHECK_EQUAL(a, b)</td>
<td>a == b</td>
</tr>
<tr>
<td>RBX_CHECK_NE(a,b)</td>
<td>a ~= b</td>
</tr>
<tr>
<td>RBX_CHECK_GE(a,b)</td>
<td>a >= b</td>
</tr>
<tr>
<td>RBX_CHECK_LE(a,b)</td>
<td>a <= b</td>
</tr>
<tr>
<td>RBX_CHECK_GT(a、b)</td>
<td>a > b</td>
</tr>
<tr>
<td>RBX_CHECK_LT(a、b)</td>
<td>a < b</td>
</tr>
微型

RBX_需求

這個 macro 使用 TestService:Require() 函數進行測試。


<th>測試條件</th>
</tr>
<tr>
<td>RBX_REQUIRE(條件)</td>
<td>cond == 真實</td>
</tr>
<tr>
<td>RBX_REQUIRE_MESSAGE(條件, 失敗訊息)</td>
<td>cond == 真實</td>
</tr>
<tr>
<td>RBX_REQUIRE_THROW(代碼)</td>
<td>pcall(function() 代碼結束) == 否</td>
</tr>
<tr>
<td>RBX_REQUIRE_NO_THROW(代碼)</td>
<td>pcall(function() 代碼結束) == 真</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>cond == 真實</td>
</tr>
<tr>
<td>RBX_WARN_MESSAGE(條件,失敗訊息)</td>
<td>cond == 真實</td>
</tr>
<tr>
<td>RBX_WARN_THROW(代碼)</td>
<td>pcall(function() 代碼結束) == 否</td>
</tr>
<tr>
<td>RBX_WARN_NO_THROW(代碼)</td>
<td>pcall(function() 代碼結束) == 真</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>
微型

額外的微型型號


<th>說明</th>
</tr>
<tr>
<td>RBX_ERROR(訊息)</td>
<td>直接呼叫 <code>Class.TestService:Error()</code> 函數。</td>
</tr>
<tr>
<td>RBX_FAULT(訊息)</td>
<td>直接呼叫 <code>Class.TestService:Fail()</code> 函數。</td>
</tr>
<tr>
<td>RBX_MESSAGE(訊息)</td>
<td>直接呼叫 <code>Class.TestService:Message()</code> 功能。</td>
</tr>
微型

概要

屬性

方法

活動

屬性

AutoRuns

平行讀取

如果設為真值,遊戲將在測試服務的 TestService:Run() 方法被呼叫時開始運行。

Description

平行讀取

執行測試的說明。

ErrorCount

唯讀
未複製
平行讀取

記錄測試會作業中發生的錯誤數量。

ExecuteWithStudioRun

平行讀取

當設為真實時,測試服務將在 Roblox Studio 中使用 執行 行動時執行。

注意:

  • 如果 TestService.NumberOfPlayers 屬性設為 0 以上的值,運行遊戲將開啟 NumberOfPlayers + 1 工作室窗口,其中一個窗口是服務伺服器,其余的是與服務伺服器連接的玩家。
  • 嘗試將此值保持在合理範圍內(最多 8 名玩家),否則您的電腦 CPU 將無法承受負荷。

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

()

指示在測試服務運行時發生致命錯誤。如果在測試服務內執行的腳本中呼叫此操作,將啟動在呼叫錯誤的線上的暫停點。

參數

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

()
暫停
外掛程式安全性

執行與測試服務親和的腳本。


返回

()

活動

ServerCollectConditionalResult

當伺服器應該收集條件測試結果時,發射時間。

參數

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

ServerCollectResult

當伺服器應該收集測試結果時發射。

參數

text: string
script: Instance
line: number