Swan Lake Beta3 is here.
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
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
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand