import ballerina/test;
import ballerina/io;
@test:BeforeEach
function beforeFunc () {
io:println("I'm the before function!");
}
@test:Config
function testFunction1 () {
io:println("I'm in test function 1!");
test:assertTrue(true , msg = "Failed!");
}@test:Config
function testFunction2 () {
io:println("I'm in test function 2!");
test:assertTrue(true , msg = "Failed!");
}@test:Config
function testFunction3 () {
io:println("I'm in test function 3!");
test:assertTrue(true , msg = "Failed!");
}
Testerina Before EachThe function specified with Before Each annotation will be run before every test within the test suite. This can be used for repeatedly initializing test level aspects before every test function. |
|
import ballerina/test;
import ballerina/io;
|
|
@test:BeforeEach
function beforeFunc () {
io:println("I'm the before function!");
}
|
Before test function |
@test:Config
function testFunction1 () {
io:println("I'm in test function 1!");
test:assertTrue(true , msg = "Failed!");
}
|
Test function |
@test:Config
function testFunction2 () {
io:println("I'm in test function 2!");
test:assertTrue(true , msg = "Failed!");
}
|
|
@test:Config
function testFunction3 () {
io:println("I'm in test function 3!");
test:assertTrue(true , msg = "Failed!");
}
|
|
$ ballerina test testerina-before-each.bal
T E S T S
---------------------------------------------------------------------------
---------------------------------------------------------------------------
Running Tests of Package: .
---------------------------------------------------------------------------
I'm the before function!
I'm in test function 3!
I'm the before function!
I'm in test function 2!
I'm the before function!
I'm in test function 1!
|
|
Tests run: 3, Passed: 3, Failures: 0, Skipped: 0 - in TestSuite
|
|
---------------------------------------------------------------------------
Results:
|
|
Tests run: 3, Passed: 3, Failures: 0, Skipped: 0
---------------------------------------------------------------------------
Summary:
|
|
................................................................... SUCCESS
---------------------------------------------------------------------------
|
|