import ballerina/io;
import ballerina/test;

// Executed before the first test function of the group `g1`.
@test:BeforeGroups { value:["g1"] }
function beforeGroupsFunc() {
    io:println("I'm the before groups function!");
}

// Executed after the last test function of the group `g1`.
@test:AfterGroups { value:["g1"] }
function afterGroupsFunc() {
    io:println("I'm the after groups function!");
}

// A test function belonging to the group `g1`.
@test:Config { groups: ["g1"]}
function testFunction1() {
    io:println("I'm in test function 1!");
    test:assertTrue(true, msg = "Failed!");
}

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

Before and After Groups

The function specified with the BeforeGroups annotation is executed once before all the tests belonging to the specified group is executed and the function specified with the AfterGroups annotation is executed once after all the tests belonging to the specified group is executed.

For more information, see Testing Ballerina Code and the Test Module.

import ballerina/io;
import ballerina/test;
@test:BeforeGroups { value:["g1"] }
function beforeGroupsFunc() {
    io:println("I'm the before groups function!");
}

Executed before the first test function of the group g1.

@test:AfterGroups { value:["g1"] }
function afterGroupsFunc() {
    io:println("I'm the after groups function!");
}

Executed after the last test function of the group g1.

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

A test function belonging to the group g1.

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

Another test function.

bal test test_module
Compiling source
        ballerinatest/test_module:0.1.0
Running tests
        ballerinatest/test_module:0.1.0
I'm the before groups function!
I'm in test function 1!
I'm the after groups function!
I'm in test function 2!
	[pass] testFunction1
	[pass] testFunction2
	2 passing
	0 failing
	0 skipped