Table of Contents

Codeunit "Library Assert"

ID 130002
Namespace: System.TestLibraries.Utilities

This module provides functions for easy verification of expected values and error handling in test code.

Methods

IsTrue

Tests whether the specified condition is true and throws an exception if the condition is false.

procedure IsTrue(Condition: Boolean, Msg: Text)

Parameters

Name Type Description
Condition Boolean

The condition the test expects to be true.

Msg Text

The message to include in the exception when condition is false. The message is shown in test results.

IsFalse

Tests whether the specified condition is false and throws an exception if the condition is true.

procedure IsFalse(Condition: Boolean, Msg: Text)

Parameters

Name Type Description
Condition Boolean

The condition the test expects to be false.

Msg Text

The message to include in the exception when condition is true. The message is shown in test results.

AreEqual

Tests whether the specified values are equal and throws an exception if the two values are not equal.

procedure AreEqual(ExpectedVariant: Variant, ActualVariant: Variant, Msg: Text)

Parameters

Name Type Description
ExpectedVariant Variant

The first value to compare. This is the value the tests expects.

ActualVariant Variant

The second value to compare. This is the value produced by the code under test.

Msg Text

The message to include in the exception when actual is not equal to expected. The message is shown in test results.

AreEqual

Tests whether the specified dictionaries are equal and throws an exception if the two dictionaries are not equal.

procedure AreEqual(Expected: Dictionary of [Text, Text], Actual: Dictionary of [Text, Text])

Parameters

Name Type Description
Expected Dictionary of [Text, Text]

The first dicitonary to compare.

Actual Dictionary of [Text, Text]

The second dictionary to compare.

AreEqualDateTime

Tests whether the specified DateTime values are equal and throws an exception if the two DateTime values are not equal. This function uses the high precision format type 1

procedure AreEqualDateTime(Expected: DateTime, Actual: DateTime, Msg: Text)

Parameters

Name Type Description
Expected DateTime

The first DateTime value to compare. This is the DateTime value the tests expects.

Actual DateTime

The second DateTime value to compare. This is the DateTime value produced by the code under test.

Msg Text

The message to include in the exception when actual is not equal to expected. The message is shown in test results.

AreEqualDateTime

Tests whether the specified DateTime values are nearly equal and throws an exception if the two DateTime values are not nearly equal.

procedure AreEqualDateTime(Expected: DateTime, Actual: DateTime, Delta: Duration, Msg: Text)

Parameters

Name Type Description
Expected DateTime

The first DateTime value to compare. This is the DateTime value the tests expects.

Actual DateTime

The second DateTime value to compare. This is the DateTime value produced by the code under test.

Delta Duration

The maximum difference between the two DateTime values.

Msg Text

The message to include in the exception when actual is not equal to expected. The message is shown in test results.

AreNotEqual

Tests whether the specified values are unequal and throws an exception if they are equal.

procedure AreNotEqual(ExpectedVariant: Variant, ActualVariant: Variant, Msg: Text)

Parameters

Name Type Description
ExpectedVariant Variant

The first value to compare. This is the value the test expects not to match actual.

ActualVariant Variant

The second value to compare. This is the value produced by the code under test.

Msg Text

The message to include in the exception when actual is not equal to expected. The message is shown in test results.

AreNearlyEqual

Tests whether the specified decimals are equal and throws an exception if the they are not equal.

procedure AreNearlyEqual(Expected: Decimal, Actual: Decimal, Delta: Decimal, Msg: Text)

Parameters

Name Type Description
Expected Decimal

The first value to compare. This is the value the tests expects.

Actual Decimal

The second value to compare. This is the value produced by the code under test.

Delta Decimal

The required accuracy. An exception will be thrown only if actual is different than expected by more than delta.

Msg Text

The message to include in the exception when actual is different than expected by more than delta. The message is shown in test results.

AreNotNearlyEqual

Tests whether the specified decimals are unequal and throws an exception if the they are equal.

procedure AreNotNearlyEqual(Expected: Decimal, Actual: Decimal, Delta: Decimal, Msg: Text)

Parameters

Name Type Description
Expected Decimal

The first value to compare. This is the value the tests expects not to match actual.

Actual Decimal

The second value to compare. This is the value produced by the code under test.

Delta Decimal

The required accuracy. An exception will be thrown only if actual is different than Expected by at most delta.

Msg Text

The message to include in the exception when actual is equal to Expected or different by less than delta. The message is shown in test results.

Fail

Throws an exception.

procedure Fail(Msg: Text)

Parameters

Name Type Description
Msg Text

The message to include in the exception. The message is shown in test results.

RecordIsEmpty

Tests whether the specified record is non-empty and throws an exception if it is.

procedure RecordIsEmpty(RecVariant: Variant)

Parameters

Name Type Description
RecVariant Variant

The record to be checked

RecordIsNotEmpty

Tests whether the specified record is empty and throws an exception if it is.

procedure RecordIsNotEmpty(RecVariant: Variant)

Parameters

Name Type Description
RecVariant Variant

The record to be checked

TableIsEmpty

Tests whether the specified table is non-empty and throws an exception if it is.

procedure TableIsEmpty(TableNo: Integer)

Parameters

Name Type Description
TableNo Integer

The id of table the test expects to be empty

TableIsNotEmpty

Tests whether the specified table is empty and throws an exception if it is.

procedure TableIsNotEmpty(TableNo: Integer)

Parameters

Name Type Description
TableNo Integer

The id of table the test expects not to be empty

RecordCount

Tests whether the Table holds the expected number of Records and throws an exception when the count is different.

procedure RecordCount(RecVariant: Variant, ExpectedCount: Integer)

Parameters

Name Type Description
RecVariant Variant

The table whos records will be counter

ExpectedCount Integer

The expected number of records in the table

KnownFailure

This function is used to indicate the test is known to fail with a certain error. If the last error thrown is the expected one, a known failure error is thrown. If the last error was a different error than an exception is thrown.

procedure KnownFailure(Expected: Text, WorkItemNo: Integer)

Parameters

Name Type Description
Expected Text

The expected error

WorkItemNo Integer

The Id of the workitem to fix the know test defect

ExpectedError

Verifies that the last error thrown is the expected error. If a different error was thrown, an exception is thrown.

procedure ExpectedError(Expected: Text)

Parameters

Name Type Description
Expected Text

The expected error

ExpectedErrorCode

Verifies that the last error code thrown is the expected error code. If a different error code was thrown, an exception is thrown.

procedure ExpectedErrorCode(Expected: Text)

Parameters

Name Type Description
Expected Text

The expected error code

ExpectedMessage

Tests that the Expected message matches the Actual message

procedure ExpectedMessage(Expected: Text, Actual: Text)

Parameters

Name Type Description
Expected Text

The first value to compare. This is the value the tests expects not to match actual.

Actual Text

The second value to compare. This is the value produced by the code under test.

AssertRecordNotFound

Verifies that the last error code thrown was the Record Not Found error code.

procedure AssertRecordNotFound()

AssertRecordAlreadyExists

Verifies that the last error code thrown was the Record Already Exists error code.

procedure AssertRecordAlreadyExists()

AssertNothingInsideFilter

Verifies that the last error code thrown was the Nothing Inside Filter error code.

procedure AssertNothingInsideFilter()

AssertNoFilter

Verifies that the last error code thrown was the No Filter error code.

procedure AssertNoFilter()

AssertPrimRecordNotFound

Verifies that the last error code thrown was the Primary Record Not Found error code.

procedure AssertPrimRecordNotFound()

See also