import ballerina/test;
import ballerina/io;
@test:BeforeSuite
function beforeFunc () {
    io:println("I'm the before suite function!");
}
@test:Config
function testFunction1 () {
    io:println("I'm in test function 1!");
    test:assertTrue(true , msg = "Failed");
}
@test:Config
function testFunction2 () {
    io:println("I'm in test function 2!");
    test:assertTrue(true , msg = "Failed");
}
@test:AfterSuite
function afterFunc () {
    io:println("I'm the after suite function!");
}

Testerina Before After Suite

BeforeSuite feature allows you to execute an function before executing a test suite. A package is considered as a suite in testerina. This capability can be used for setting up prerequisites before executing a test suite. In the same way AfterSuite annotation can be used to execute a function after a test suite.

import ballerina/test;
import ballerina/io;
@test:BeforeSuite
function beforeFunc () {
    io:println("I'm the before suite function!");
}

Before suite function

@test:Config
function testFunction1 () {
    io:println("I'm in test function 1!");
    test:assertTrue(true , msg = "Failed");
}

Test function

@test:Config
function testFunction2 () {
    io:println("I'm in test function 2!");
    test:assertTrue(true , msg = "Failed");
}

Test function

@test:AfterSuite
function afterFunc () {
    io:println("I'm the after suite function!");
}

After suite function

$ ballerina test testerina-before-after-suite.bal
---------------------------------------------------------------------------
    T E S T S
---------------------------------------------------------------------------
---------------------------------------------------------------------------
Running Tests of Package: .
---------------------------------------------------------------------------
I'm the before suite function!
I'm in test function 1!
I'm in test function 2!
I'm the after suite function!
Tests run: 2, Passed: 2, Failures: 0, Skipped: 0 - in TestSuite
---------------------------------------------------------------------------
Results:
Tests run: 2, Passed: 2, Failures: 0, Skipped: 0
---------------------------------------------------------------------------
Summary:
................................................................... SUCCESS
---------------------------------------------------------------------------