Test
Package: Libraries.Testing · Inherits from: Libraries.Language.Object
This class represents an abstract test on the system. It can either be instantiated and its state altered or it can be subclassed and executed externally, by a tester or otherwise. Inside it contains a series of helper actions for having one or more value checks. By default, if this test receives a check and at least one of these checks fails, the overall test fails on a run.
Example Code
use Libraries.Testing.Tester
use Libraries.Testing.Test
Tester tests
Test result
result:SetMessage("This is a failed test.")
tests:Add(result)
Actions
Check(number value, number expected)
This action checks whether two number values are equal, using the default threshold value as the difference allowed.
Parameters
valuenumberexpectednumber
Returns
boolean
Example
use Libraries.Testing.Test
Test result
output result:Check(0.01, 0.02) //false
Check(boolean value, boolean expected)
This action checks whether two values are equal.
Parameters
valuebooleanexpectedboolean
Returns
boolean
Example
use Libraries.Testing.Test
Test result
output result:Check(true, false) //false
Check(number value, number expected, number difference)
This action checks whether two number values are equal, using the default threshold value as the difference allowed.
Parameters
valuenumberexpectednumberdifferencenumber
Returns
boolean
Example
use Libraries.Testing.Test
Test result
output result:Check(0.01, 0.02, 0.01) //true
Check(integer value, number expected)
This action checks whether two values are equal.
Parameters
valueintegerexpectednumber
Returns
boolean
Example
use Libraries.Testing.Test
Test result
output result:Check(1, 2) //false
Check(text value, text expected)
This action checks whether two values are equal.
Parameters
valuetextexpectedtext
Returns
boolean
Example
use Libraries.Testing.Test
Test result
output result:Check("Hi", "Not Hi") //false
GetErrorMessage()
Returns an error message from the test.
Returns
text: the message
GetMessage()
Returns a message from the test.
Returns
text: the message
GetName()
Returns the name of the test. Tests do not have a name by default.
Returns
text: the name
GetThreshold()
Returns the default threshold for the comparison of two numbers.
Returns
number: the threshold, which is equivalent to me:threshold
HasThrewError()
Returns whether or not this test threw an error while it executed.
Returns
boolean: true if it threw an error
IsPassed()
This action returns true if the test passed. By default, it returns false. If even a single check call failed, this test fails unless SetPassed is called explicitly.
Returns
boolean: true if the test passed.
Run()
This action executes the test. By default, it does nothing.
Example
use Libraries.Testing.Tester
use Libraries.Testing.Test
Tester tests
Test result
result:SetMessage("This is a failed test.")
tests:Run(result)
SetErrorMessage(text error)
Sets an error message from the test.
Parameters
errortext: the message
SetMessage(text message)
Sets a error message from the test.
Parameters
messagetext
SetName(text name)
Sets the name of the test
Parameters
nametext: the name of the test
SetPassed(boolean passed)
This action tells the test whether or not it passed.
Parameters
passedboolean: tells the test to indicate that it passed
SetThreshold(number threshold)
Sets the default threshold for the comparison of two numbers.
Parameters
thresholdnumber: the threshold, which is equivalent to me:threshold
SetThrewError(boolean threwError)
Sets whether or not this test threw an error while it executed.
Parameters
threwErrorboolean: Sets whether this test through an error