import ballerina/test;
import ballerina/io;
function beforeFunc () {
io:println("I'm the before function!");
}
@test:Config{
before:"beforeFunc",
after:"afterFunc"
}
function testFunction () {
io:println("I'm in test function!");
test:assertTrue(true , msg = "Failed!");
}
function afterFunc () {
io:println("I'm the after function!");
}
Testerina Before AfterBefore attribute allows you to execute an function before a test function. This capability can be used for setting up prerequisites for before executing a test. In the same way after attribute can be used to execute a function after a test function |
|
import ballerina/test;
import ballerina/io;
|
|
function beforeFunc () {
io:println("I'm the before function!");
}
|
Before test function |
@test:Config{
before:"beforeFunc",
after:"afterFunc"
}
function testFunction () {
io:println("I'm in test function!");
test:assertTrue(true , msg = "Failed!");
}
|
Test function |
function afterFunc () {
io:println("I'm the after function!");
}
|
after test function |
$ ballerina test testerina-before-after.bal
---------------------------------------------------------------------------
T E S T S
---------------------------------------------------------------------------
---------------------------------------------------------------------------
Running Tests of Package: .
---------------------------------------------------------------------------
I'm the before function!
I'm in test function!
I'm the after function!
|
|
Tests run: 1, Passed: 1, Failures: 0, Skipped: 0 - in TestSuite
|
|
---------------------------------------------------------------------------
Results:
|
|
Tests run: 1, Passed: 1, Failures: 0, Skipped: 0
---------------------------------------------------------------------------
Summary:
|
|
................................................................... SUCCESS
---------------------------------------------------------------------------
|
|