Skip to content

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) {
    require(n > threshold, "n must exceed the threshold");
};

@test
function testFailsPassing(test: Test) -> {
    // Test passes because the `require` clause fails.
    var message = test.assertFails(function() returns Foo -> Foo['p'](belowThreshold));
};

@test
function testFailsPassingWithMessage(test: Test) -> {
    // Test passes because the `require` clause fails.
    var message = test.assertFails(function() returns Foo -> Foo['p'](belowThreshold), "`require` clause failure expected.");
};

@test
function testFailsFailing(test: Test) -> {
    // Test fails because `require` 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 `require` is R14
    test.assertFailsWith(function() -> Foo['p'](belowThreshold), 14);
};
// This test fails because the error code thrown by a failing `require` 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);
};

expectNotifications

<function> Asserts whether a specific number of notification was emitted with the given predicate.

Receiver

Test

Type Arguments

Protocol

Notification

Predicate

Arguments

proto - Protocol - : Protocol must be a protocol instance from which the notification is expected to have been sent

notif - Notification - : Notification must be the notification by-name which is expected to have been sent

count - Number - : Number the expected number of notifications matching the predicate

predicate - Predicate - : Predicate must be a functional type with Boolean return type taking as arguments the same in-order argument types as its aforementioned notification n: N. Its evaluation should always succeed with either true or false. If the notification has no arguments, the function type should also have no arguments. The arguments are passed with the notification values that were emitted.

Usage
notification NoEarthquake() returns Unit;
notification Earthquake(a: Number, b: Text) returns Unit;
notification Aftershock(scale: Number) returns Unit;

protocol[a] Mountain() {
    permission[a] quake() {
        notify NoEarthquake();
        notify Earthquake(5, "2");
        notify Aftershock(3);
    };
};

@test
function testMyNotifications(test: Test) -> {
    var m = Mountain['a']();
    m.quake['a']();

    test.expectNotifications(m, NoEarthquake, 1, function() returns Boolean -> true);
    test.expectNotifications(m, Earthquake, 1, function(a: Number, b: Text) returns Boolean -> a == 5 && b == "2");
    test.expectNotifications(m, Aftershock, 0, function(scale: Number) -> scale > 3);
};

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