Test
Default type of any test method. See Testing.
Methods
assertEquals
<function> Asserts that two values are equal. Optionally a message may be provided that is displayed instead of the default message.
Receiver
Test
Type Arguments
T
Arguments
expected - T
actual - T
optional message - Text
Usage
@test
function testEqPassing(test: Test) -> {
test.assertEquals(someValue, theSameValue);
};
@test
function testEqPassingWithMessage(test: Test) -> {
test.assertEquals(someValue, theSameValue, "The number of boxes should equal the number of shipped products.");
};
@test
function testEqFailing(test: Test) -> {
test.assertEquals(someValue, someOtherValue);
};
assertFails
<function> Run an action that is expected to fail. If the action fails as expected, the test passes and the result contains the corresponding failure message. If the action does not fail, the test fails. Optionally a message may be provided that is displayed instead of the default message.
Receiver
Test
Type Arguments
T
Arguments
action - () -> T
optional message - Text
Returns
Text
Usage
protocol[p] Foo(n: Number) {
guard(n > threshold, "n must exceed the threshold");
};
@test
function testFailsPassing(test: Test) -> {
// Test passes because the guard fails.
var message = test.assertFails(function() returns Foo -> Foo['p'](belowThreshold));
};
@test
function testFailsPassingWithMessage(test: Test) -> {
// Test passes because the guard fails.
var message = test.assertFails(function() returns Foo -> Foo['p'](belowThreshold), "Guard failure expected.");
};
@test
function testFailsFailing(test: Test) -> {
// Test fails because the guard does not fail.
test.assertFails(function() returns Foo -> Foo['p'](aboveThreshold));
};
assertFailsWith
<function> Run an action that is expected to fail with a specific runtime error code. If the action fails as expected, the test passes and the result contains the corresponding failure message. If the action does not fail, the test fails. Optionally a message may be provided that is displayed instead of the default message.
Receiver
Test
Type Arguments
T
Arguments
action - () -> T
runtimeError - Number
optional message - Text
Returns
Text
Usage
See Errors for the runtime error codes that can be used.
@test
function testsFailsWithPasses(test: Test) -> {
// This test passes because the error code thrown by a failing guard is R14
test.assertFailsWith(function() -> Foo['p'](belowThreshold), 14);
};
// This test fails because the error code thrown by a failing guard is R14, not R15
test.assertFailsWith(function() -> Foo['p'](belowThreshold), 15)
assertFalse
<function>
Asserts that the provided value is false
. Optionally a message may be provided that is displayed instead of the default message.
Receiver
Test
Arguments
actual - Boolean
optional message - Text
Usage
@test
function testFalsePassing(test: Test) -> {
test.assertFalse(conditionFalse);
};
@test
function testFalsePassingWithMessage(test: Test) -> {
test.assertFalse(conditionFalse, "The pump should be off.");
};
@test
function testFalseFailing(test: Test) -> {
test.assertFalse(conditionTrue);
};
assertNotEquals
<function> Asserts that two values are not equal. Optionally a message may be provided that is displayed instead of the default message.
Receiver
Test
Type Arguments
T
Arguments
notExpected - T
actual - T
optional message - Text
Usage
@test
function testNePassing(test: Test) -> {
test.assertNotEquals(someValue, anotherValue);
};
@test
function testNePassingWithMessage(test: Test) -> {
test.assertNotEquals(someValue, anotherValue, "After delivery the target should have been updated.");
};
@test
function testNeFailing(test: Test) -> {
test.assertNotEquals(someValue, sameValue);
};
assertTrue
<function>
Asserts that the provided value is true
. Optionally a message may be provided that is displayed instead of the default message.
Receiver
Test
Arguments
actual - Boolean
optional message - Text
Usage
@test
function testTruePassing(test: Test) -> {
test.assertTrue(conditionThatIsTrue);
};
@test
function testTruePassingWithMessage(test: Test) -> {
test.assertTrue(conditionThatIsTrue, "The pump should have been turned on.");
};
@test
function testTrueFailing(test: Test) -> {
test.assertTrue(conditionThatIsFalse);
};
comment
<function> Sets an additional message that will be printed during the test.
Receiver
Test
Arguments
message - Text
Returns
Test
setTime
<function> Sets the internal scheduler and runtime clock during testing.
Receiver
Test
Arguments
dateTime - DateTime
Returns
DateTime
sleep
<function>
Calls Thread.sleep(...)
internally for millis
milliseconds.
Receiver
Test
Arguments
millis - Number