PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TestService

Show deprecated

TestService

Show deprecated

The TestService is a service used by Roblox internally to run analytical tests on their engine.
It makes it possible to write sophisticated tests right inside a game.

Macros

Scripts that are executed inside of the TestService (via TestService/Run) have access to special macros that directly invoke functions under the TestService. Macros are essentially substitutions for large blocks of code that shouldn’t need to be rewritten each time you want to call them.

RBX_CHECK

This macro does tests with calls to the TestService/Check function.

Macro Test Condition
RBX_CHECK(cond) cond == true
RBX_CHECK_MESSAGE(cond, failMsg) cond == true
RBX_CHECK_THROW(CODE) pcall(function () CODE end) == false
RBX_CHECK_NO_THROW(CODE) pcall(function () CODE end) == true
RBX_CHECK_EQUAL(a,b) a == b
RBX_CHECK_NE(a,b) a ~= b
RBX_CHECK_GE(a,b) a >= b
RBX_CHECK_LE(a,b) a <= b
RBX_CHECK_GT(a,b) a > b
RBX_CHECK_LT(a,b) a < b

RBX_REQUIRE

This macro does tests with calls to the TestService/Require function.

Macro Test Condition
RBX_REQUIRE(cond) cond == true
RBX_REQUIRE_MESSAGE(cond, failMsg) cond == true
RBX_REQUIRE_THROW(CODE) pcall(function () CODE end) == false
RBX_REQUIRE_NO_THROW(CODE) pcall(function () CODE end) == true
RBX_REQUIRE_EQUAL(a,b) a == b
RBX_REQUIRE_NE(a,b) a ~= b
RBX_REQUIRE_GE(a,b) a >= b
RBX_REQUIRE_LE(a,b) a <= b
RBX_REQUIRE_GT(a,b) a > b
RBX_REQUIRE_LT(a,b) a < b

RBX_WARN

This macro does tests with calls to the TestService/Warn function.

Macro Test Condition
RBX_WARN(cond) cond == true
RBX_WARN_MESSAGE(cond, failMsg) cond == true
RBX_WARN_THROW(CODE) pcall(function () CODE end) == false
RBX_WARN_NO_THROW(CODE) pcall(function () CODE end) == true
RBX_WARN_EQUAL(a,b) a == b
RBX_WARN_NE(a,b) a ~= b
RBX_WARN_GE(a,b) a >= b
RBX_WARN_LE(a,b) a <= b
RBX_WARN_GT(a,b) a > b
RBX_WARN_LT(a,b) a < b

Additional Macros

Macro Description
RBX_ERROR(msg) Directly calls the `TestService/Error` function.
RBX_FAIL(msg) Directly calls the `TestService/Fail` function.
RBX_MESSAGE(msg) Directly calls the `TestService/Message` function.

See Also

Properties

bool

AutoRuns

If set to true, the game will start running when the TestService’s TestService/Run method is called.

string

Description

A description of the test being executed.

int

ErrorCount

[ReadOnly] [NotReplicated]

Measures how many errors have been recorded in the test session.

bool

ExecuteWithStudioRun

When set to true, the TestService will be executed when using the Run action in Roblox Studio.

bool

Is30FpsThrottleEnabled

Sets whether or not the physics engine should be throttled to 30 FPS while the test is being ran.

bool

IsPhysicsEnvironmentalThrottled

Sets whether or not the physics environment should be throttled while running this test.

bool

IsSleepAllowed

Sets whether or not physics objects will be allowed to fall asleep while the test simulation is running.

int

NumberOfPlayers

The number of players expected in this test, if any.

double

SimulateSecondsLag

Sets a specific amount of additional latency experienced by players during the test session.

int

TestCount

[ReadOnly] [NotReplicated]

Measures how many test calls have been recorded in the test session.

double

Timeout

The maximum amount of time that tests are allowed to run for.

int

WarnCount

[ReadOnly] [NotReplicated]

Measures how many warning calls have been recorded in the test session.

Inherited from Instance: Show Hide

int

DataCost

[ReadOnly] [NotReplicated]
The cost of saving the instance using data persistence.
Instance

Parent

Determines the hierarchical parent of the `Instance`.
bool

RobloxLocked

If true, the `Instance` and its descendants cannot be indexed or edited by a `Script` or `LocalScript` and will throw an error if it is attempted.
string

ClassName

[ReadOnly] [NotReplicated]
A read-only string representing the class this `Instance` belongs to.
string

Name

A non-unique identifier of the `Instance`.
bool

Archivable

Determines if an `Instance` can be cloned using `/Instance/Clone` or saved to file.

Functions

void

Check ( bool condition , string description , Instance source , int line )

Prints result of condition to output.

void

Checkpoint ( string text , Instance source , int line )

Prints "Test checkpoint: ", followed by text, to the output, in blue text.

void

Done ( )

Prints Testing Done to the output, in blue text.

void

Error ( string description , Instance source , int line )

Prints a red message to the output.

void

Fail ( string description , Instance source , int line )

Indicates a fatal error in a TestService run.

If this is called inside of a script running inside of the TestService, this will initiate a breakpoint on the line that invoked the error.

void

Message ( string text , Instance source , int line )

Prints Test message, followed by text to the output, in blue text.

void

Require ( bool condition , string description , Instance source , int line )

Prints whether a condition is true along with description text.

void

Run ( )

[Yields]

Runs scripts which are parented to TestService.

void

Warn ( bool condition , string description , Instance source , int line )

Prints if a condition is true, otherwise prints a warning.

bool

isFeatureEnabled ( string name )

Inherited from Instance: Show Hide

RBXScriptSignal

GetPropertyChangedSignal ( string property )

Get an event that fires when a given property of an object changes.
Instance

FindFirstChildWhichIsA ( string className , bool recursive )

Returns the first child of the `Instance` for whom `Instance/IsA` returns true for the given className.
Array

GetDescendants ( )

[CustomLuaState]
Returns an array containing all of the `Instance`'s descendants.
bool

IsAncestorOf ( Instance descendant )

Returns true if an `Instance` is an ancestor of the given descendant.
bool

IsDescendantOf ( Instance ancestor )

Returns true if an `Instance` is a descendant of the given ancestor.
Instance

FindFirstChildOfClass ( string className )

Returns the first child of the `Instance` whose `Instance/ClassName|ClassName` is equal to the given className.
Instance

FindFirstChild ( string name , bool recursive )

Returns the first child of the `Instance` found with the given name.
Instance

FindFirstAncestorWhichIsA ( string className )

Returns the first ancestor of the `Instance` for whom `Instance/IsA` returns true for the given className.
Instance

FindFirstAncestorOfClass ( string className )

Returns the first ancestor of the `Instance` whose `Instance/ClassName` is equal to the given className.
Instance

FindFirstAncestor ( string name )

Returns the first ancestor of the `Instance` whose `Instance/Name` is equal to the given name.
bool

IsA ( string className )

Returns true if an `Instance`'s class matches or inherits from a given class
Instance

WaitForChild ( string childName , double timeOut )

[CustomLuaState] [CanYield]
Returns the child of the `Instance` with the given name. If the child does not exist, it will yield the current thread until it does.
string

GetFullName ( )

Returns a string showing the `Instance`'s ancestry.
string

GetDebugId ( int scopeLength )

[NotBrowsable]
Returns a coded string of the `Instance`s DebugId used internally by Roblox.
Objects

GetChildren ( )

Returns an array containing all of the `Instance`'s children.
void

Destroy ( )

Sets the `Instance/Parent` property to nil, locks the `Instance/Parent` property, disconnects all connections and calls Destroy on all children.
Instance

Clone ( )

Create a deep copy of a Roblox instance and descendants where `Archivable = true`.
void

ClearAllChildren ( )

This function destroys all of an `Instance`'s children.

Events

RBXScriptSignal

ServerCollectConditionalResult ( bool condition , string text , Instance script , int line )

Fired when the server should collect a conditional test result.

RBXScriptSignal

ServerCollectResult ( string text , Instance script , int line )

Fired when the server should collect a test result.

Inherited from Instance: Show Hide

RBXScriptSignal

DescendantRemoving ( Instance descendant )

Fires immediately before a descendant of the `Instance` is removed.
RBXScriptSignal

AncestryChanged ( Instance child , Instance parent )

Fires when the `Instance/Parent` property of the object or one of its ancestors is changed.
RBXScriptSignal

ChildAdded ( Instance child )

Fires when an object is parented to this `Instance`.
RBXScriptSignal

ChildRemoved ( Instance child )

Fires when a child is removed from this `Instance`.
RBXScriptSignal

DescendantAdded ( Instance descendant )

Fires when a descendant is added to the `Instance`.
RBXScriptSignal

Changed ( string property )

Fired immediately after a property of an object changes.