Unit Test Functions
Functions that allow you to create test cases and test conditions
assertEquals
A test to check if 2 variables or values are exactly equal
Syntax
assertEquals(expected, value, optional message)
Example
greeting = "Hello"
obj = Object()
obj.name = "John"
obj.value = 23
// You can directly test variables
assertEquals("Hello", greeting)
// You can test properties
assertEquals(23, obj.value)
// You can test expressions
assertEquals(23, 14 + 9)
If the test fails, an exception is thrown
The optional message on each function is a custom exception message that can be used if the test fails
assertFalse
A test to check if an expression is false (not true)
Syntax
assertFalse(expression, optional message)
Example
obj = Object()
obj.name = "John"
obj.value = 23
// You can test a variable or variable property
b = obj.value > 25
obj.test = b
assertFalse(b)
assertFalse(obj.test)
// You can test an expression
assertFalse(12>13)
If the test fails, an exception is thrown
The optional message on each function is a custom exception message that can be used if the test fails
assertHasProperty
A test to check if a variable has the specified named property
Syntax
assertHasProperty(var, property)
Example
obj = Object()
obj.name = "John"
obj.value = 23
assertHasProperty(obj, "name")
If the test fails, an exception is thrown
The optional message on each function is a custom exception message that can be used if the test fails
assertNull
A test to check if a variable is null
Syntax
assertNull(var)
Example
obj = Object()
obj.name = "John"
obj.value = 23
// obj doesn't have a property called description
assertNull(obj.description)
If the test fails, an exception is thrown
The optional message on each function is a custom exception message that can be used if the test fails
assertTrue
Tests to see if a value or expression is true
Syntax
assertTrue(var, optional message)
Example
obj = Object()
obj.name = "John"
obj.value = 23
// You can test a variable or variable property
b = obj.value < 25
obj.test = b
assertTrue(b)
assertTrue(obj.test)
// You can test an expression
assertTrue(12<13)
If the test fails, an exception is thrown
The optional message on each function is a custom exception message that can be used if the test fails
assertType
A test to check if a variable is of a certain type
Syntax
assertType(var, type)
Example
greeting = "Hello"
obj = Object()
obj.name = "John"
obj.value = 23
// You can test scalars
assertType(greeting, "Scalar")
// You can test objects
assertType(obj, "Object")
// You can test object properties
assertType(obj.name, "Scalar")
// You can test custom types
example = type
name as String()
end
eobj = object as example
name = "John"
end
assertType(eobj, "example")
If the test fails, an exception is thrown
The optional message on each function is a custom exception message that can be used if the test fails