Swan Lake Beta3 is here.
import ballerina/io;
import ballerina/test;

// Executed before all the test functions in the module.
@test:BeforeSuite
function beforeSuit() {
    io:println("I'm the before suite function!");
}

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

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

// Executed after all the test functions in the module.
@test:AfterSuite { }
function afterSuite() {
    io:println("I'm the after suite function!");
}

Before and After Suite

The BeforeSuite annotation allows you to execute a function before executing a test suite. Similarly, the AfterSuite annotation can be used to execute a function after a test suite.

A module is considered as a suite in the Test framework.

These annotations can be used to set up prerequisites and post actions for a test suite. For more information, see Testing Ballerina Code and the Test Module.

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

Executed before all the test functions in the module.

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

A Test function.

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

A Test function.

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

Executed after all the test functions in the module.

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

// Executed before all the test functions in the module.
@test:BeforeSuite
function beforeSuit() {
    io:println("I'm the before suite function!");
}

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

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

// Executed after all the test functions in the module.
@test:AfterSuite { }
function afterSuite() {
    io:println("I'm the after suite function!");
}

Before and After Suite

The BeforeSuite annotation allows you to execute a function before executing a test suite. Similarly, the AfterSuite annotation can be used to execute a function after a test suite.

A module is considered as a suite in the Test framework.

These annotations can be used to set up prerequisites and post actions for a test suite. For more information, see Testing Ballerina Code and the Test Module.

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

Executed before all the test functions in the module.

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

A Test function.

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

A Test function.

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

Executed after all the test functions in the module.

bal test test_module
Compiling source
        ballerinatest/test_module:0.1.0
Running tests
        ballerinatest/test_module:0.1.0
I'm the before suite function!
I'm in test function 1!
I'm in test function 2!
I'm the after suite function!
                [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