Functions - test

assertEquals
I

Asserts whether the given values are equal.

assertExactEquals
I

Asserts whether the given values are exactly equal.

assertFail
I

Assert failure is triggered based on user discretion.

assertFalse
I

Asserts whether the given condition is false.

assertNotEquals
I

Asserts whether the given values are not equal.

assertNotExactEquals
I

Asserts whether the given values are not exactly equal.

assertTrue
I

Asserts whether the given condition is true.

createBallerinaError
I

Creates an AssertError with custom message and category.

mock
I

Creates and returns a mock object of provided type description.

mockHandler
I

Inter-op to handle function mocking.

prepare
I

Prepares a provided default mock object for stubbing.

when
I

Objects and functions related to function mocking Allows a function to stub.

assertEquals

(anydata | error actual, anydata | error expected, string msg)

Isolated Function

Asserts whether the given values are equal. If it is not, an AssertError is thrown with the given errorMessage.

Parameters

  • actual anydata | error
  • Actual value

  • expected anydata | error
  • Expected value

  • msg string (default Assertion Failed!)
  • Assertion error message

assertExactEquals

(any | error actual, any | error expected, string msg)

Isolated Function

Asserts whether the given values are exactly equal. If it is not, an AssertError is thrown with the given errorMessage.

Parameters

  • actual any | error
  • Actual value

  • expected any | error
  • Expected value

  • msg string (default Assertion Failed!)
  • Assertion error message

assertFail

(string msg)

Isolated Function

Assert failure is triggered based on user discretion. AssertError is thrown with the given errorMessage.

Parameters

  • msg string (default Test Failed!)
  • Assertion error message

assertFalse

(boolean condition, string msg)

Isolated Function

Asserts whether the given condition is false. If it is not, a AssertError is thrown with the given errorMessage.

Parameters

  • condition boolean
  • Boolean condition to evaluate

  • msg string (default Assertion Failed!)
  • Assertion error message

assertNotEquals

(anydata | error actual, anydata | error expected, string msg)

Isolated Function

Asserts whether the given values are not equal. If it is equal, an AssertError is thrown with the given errorMessage.

Parameters

  • actual anydata | error
  • Actual value

  • expected anydata | error
  • Expected value

  • msg string (default Assertion Failed!)
  • Assertion error message

assertNotExactEquals

(any | error actual, any | error expected, string msg)

Isolated Function

Asserts whether the given values are not exactly equal. If it is equal, an AssertError is thrown with the given errorMessage.

Parameters

  • actual any | error
  • Actual value

  • expected any | error
  • Expected value

  • msg string (default Assertion Failed!)
  • Assertion error message

assertTrue

(boolean condition, string msg)

Isolated Function

Asserts whether the given condition is true. If it is not, a AssertError is thrown with the given errorMessage.

Parameters

  • condition boolean
  • Boolean condition to evaluate

  • msg string (default Assertion Failed!)
  • Assertion error message

createBallerinaError

(string errorMessage, string category)

returns error
Isolated Function

Creates an AssertError with custom message and category.

Parameters

  • errorMessage string
  • Custom message for the ballerina error

  • category string
  • error category

  • Return Type

    (error)
  • an AssertError with custom message and category

mock

(typedesc T, object { } mockObject)

returns T
Isolated Function

Creates and returns a mock object of provided type description.

Parameters

  • T typedesc
  • type of object to create the mock

  • mockObject object { } (default <object { }> object { } $obj$ = BLangTypeInit: new $init$ ([]) ; $init$())
  • mock object to replace the original (optional)

  • Return Type

    (T)
  • created mock object or throw an error if validation failed

mockHandler

(MockFunction mockFunction, any | error... args)

returns any | Error
Isolated Function

Inter-op to handle function mocking.

Parameters

  • args any | error...
  • function arguments

  • Return Type

    (any | Error)
  • function return value or error if case registration failed

prepare

(object { } mockObject)

returns MockObject
Isolated Function

Prepares a provided default mock object for stubbing.

Parameters

  • mockObject object { }
  • created default mock object

  • Return Type

    (MockObject)
  • prepared object that allows a member function/field to register stubs

when

(MockFunction mockFunction)

returns FunctionStub
Isolated Function

Objects and functions related to function mocking Allows a function to stub.

Parameters

  • Return Type

    (FunctionStub)
  • object that allows stubbing calls to provided function