The Ballerina language has a built-in robust test framework, which allows you to achieve multiple levels of the test pyramid including, unit testing, integration testing, and end-to-end testing. It provides assertions, data providers, mocking, and code coverage features, which enable the programmers to write comprehensive tests.
To get started, let's set up the Ballerina package to run tests.
Create a Ballerina package with the
bal newcommand as follows.
$ bal new hello_world
Create a directory in the root directory of the package named
testsin which the test files will be stored.
hello_world/ Ballerina.toml main.bal tests/ main_test.bal
Create the following function in the
main_test.balfile, make use of the test module to test out the functionality of the
intAddfunction in the
Execute the tests using the following command.
$ bal test
Then you can see the output as follows.
Compiling source user/hello_world:0.1.0 Running Tests hello 1 passing 0 failing 0 skipped