ballerina/test module

Module Detail

Records

Record Description
MockConfig Configuration of the function to be mocked.
TestConfig Configuration set for test functions.

Functions

Function Description
assertEquals

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

assertFail

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

assertFalse

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

assertNotEquals

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

assertTrue

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

createBallerinaError

Creates an AssertError with custom message and category.

startServiceSkeleton

Start a service skeleton from a given OpenApi definition in the given ballerina module.

startServices

Starts all the services defined in the module specified in the 'moduleName' argument.

stopServiceSkeleton

Stop a service skeleton and cleanup created directories of a given ballerina module.

stopServices

Stops all the services defined in the module specified in the 'moduleName' argument.

Annotations

Name Attaches To Data Type Description
AfterEach function -

Identifies afterTest function.

AfterSuite function -

Identifies afterSuite function.

BeforeEach function -

Identifies beforeTest function.

BeforeSuite function -

Identifies beforeSuite function.

Config function TestConfig
Mock function MockConfig

public type MockConfig

Configuration of the function to be mocked.

Field Name Data Type Default Value Description
moduleName string .

Name of the module that the function to be mocked resides in

functionName string

Name of the function to be mocked

public type TestConfig

Configuration set for test functions.

Field Name Data Type Default Value Description
enable boolean true

Flag to enable/disable test functions

groups string[] []

List of groups that this test function belongs to

dataProvider string

Name of the function which will be used to feed data into this test

before string

Name of the function to be run before the test is run

after string

Name of the function to be run after the test is run

dependsOn string[] []

A list of function names the test function depends on, and will be run before the test

public function assertEquals(any|error actual, any|error expected, string msg)

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

Parameter Name Data Type Default Value Description
actual any|error

Actual value

expected any|error

Expected value

msg string Assertion Failed!

Assertion error message

public function assertFail(string msg)

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

Parameter Name Data Type Default Value Description
msg string Test Failed!

Assertion error message

public function assertFalse(boolean condition, string msg)

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

Parameter Name Data Type Default Value Description
condition boolean

Boolean condition to evaluate

msg string Assertion Failed!

Assertion error message

public function assertNotEquals(any|error actual, any|error expected, string msg)

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

Parameter Name Data Type Default Value Description
actual any|error

Actual value

expected any|error

Expected value

msg string Assertion Failed!

Assertion error message

public function assertTrue(boolean condition, string msg)

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

Parameter Name Data Type Default Value Description
condition boolean

Boolean condition to evaluate

msg string Assertion Failed!

Assertion error message

public function createBallerinaError(string errorMessage, string category) returns (error<>)

Creates an AssertError with custom message and category.

Parameter Name Data Type Default Value Description
errorMessage string

Custom message for the ballerina error

category string

error category

Return Type Description
error<>

an AssertError with custom message and category

public function startServiceSkeleton(string moduleName, string openApiFilePath) returns (boolean)

Start a service skeleton from a given OpenApi definition in the given ballerina module.

Parameter Name Data Type Default Value Description
moduleName string

Name of the module

openApiFilePath string

Path to the OpenApi definition

Return Type Description
boolean

true if the service skeleton was started successfully, false otherwise

public function startServices(string moduleName) returns (boolean)

Starts all the services defined in the module specified in the 'moduleName' argument.

Parameter Name Data Type Default Value Description
moduleName string

Name of the module

Return Type Description
boolean

true if the services were started successfully, false otherwise

public function stopServiceSkeleton(string moduleName)

Stop a service skeleton and cleanup created directories of a given ballerina module.

Parameter Name Data Type Default Value Description
moduleName string

Name of the module

public function stopServices(string moduleName)

Stops all the services defined in the module specified in the 'moduleName' argument.

Parameter Name Data Type Default Value Description
moduleName string

Name of the module