Module : test

Module overview

This module allow developers to write testable code.

Samples

Following sample shows how to use assertions in Testerina.


import ballerina/test;

@test:Config{}
function testAssertIntEquals() {
    int answer = 0;
    int a = 5;
    int b = 3;
    answer = intAdd(a, b);
    test:assertEquals(answer, 8, msg = "int values not equal");
}

function intAdd(int a, int b) returns (int) {
    return (a + b);
}

Records

MockConfig

Configuration of the function to be mocked.

TestConfig

Configuration set for test functions.

Functions

assertEquals

Asserts whether the given values are equal.

assertFail

Assert failure is triggered based on user discretion.

assertFalse

Asserts whether the given condition is false.

assertNotEquals

Asserts whether the given values are not equal.

assertTrue

Asserts whether the given condition is true.

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

AfterEach

Identifies afterTest function.

AfterSuite

Identifies afterSuite function.

BeforeEach

Identifies beforeTest function.

BeforeSuite

Identifies beforeSuite function.

Config
Mock