import ballerina/io;
import ballerina/test;
@test:Config {
    groups: ["g1"]
}
function testFunction1() {
    io:println("I'm in test belonging to group g1!");
    test:assertTrue(true, msg = "Failed!");
}
@test:Config {
    groups: ["g1", "g2"]
}
function testFunction2() {
    io:println("I'm in test belonging to groups g1 and g2!");
    test:assertTrue(true, msg = "Failed!");
}
@test:Config {}
function testFunction3() {
    io:println("I'm the ungrouped test");
    test:assertTrue(true, msg = "Failed!");
}# To run this sample, navigate to the directory that contains the
# `.bal` file, and execute the `ballerina test` command below.
# You need to have the ballerina-tools distribution
# installed to execute this command.
ballerina test testerina_group_tests.bal --groups g1 --groups g2
Compiling tests
    testerina_group_tests.balRunning tests
    testerina_group_tests.bal
I'm in test belonging to groups g1 and g2!
I'm in test belonging to group g1!
        [pass] testFunction2
        [pass] testFunction1        2 passing
        0 failing
        0 skipped

Group Tests

You can tag your test cases with a single group name or multiple group names (one or more). This allows you to control the execution of selected tests. In order to execute tests belonging to a selected test group, you can name the test groups that are to be executed when you run tests. Likewise, you can exclude executing selected tests as well.

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

The test function, which belongs to the group g1.

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

The test function, which belongs to the groups g1 and g2

@test:Config {}
function testFunction3() {
    io:println("I'm the ungrouped test");
    test:assertTrue(true, msg = "Failed!");
}

This test doesn’t belong to any group.

# To run this sample, navigate to the directory that contains the
# `.bal` file, and execute the `ballerina test` command below.
# You need to have the ballerina-tools distribution
# installed to execute this command.
ballerina test testerina_group_tests.bal --groups g1 --groups g2
Compiling tests
    testerina_group_tests.bal
Running tests
    testerina_group_tests.bal
I'm in test belonging to groups g1 and g2!
I'm in test belonging to group g1!
        [pass] testFunction2
        [pass] testFunction1
        2 passing
        0 failing
        0 skipped
$ ballerina test testerina_group_tests.bal --groups g1
Compiling tests
    testerina_group_tests.bal
Running tests
    testerina_group_tests.bal
I'm in test belonging to groups g1 and g2!
I'm in test belonging to group g1!
        [pass] testFunction2
        [pass] testFunction1
        2 passing
        0 failing
        0 skipped
$ ballerina test testerina_group_tests.bal --disable-groups g2
Compiling tests
    testerina_group_tests.bal
Running tests
    testerina_group_tests.bal
I'm the ungrouped test
I'm in test belonging to group g1!
        [pass] testFunction3
        [pass] testFunction1
        2 passing
        0 failing
        0 skipped