- Write a RESTful API with Ballerina
- Write a gRPC service with Ballerina
- Write a GraphQL API with Ballerina
- Work with data using queries in Ballerina
- Build a data service in Ballerina
- Build a Change Data Capture (CDC) service in Ballerina
- Work with Large Language Models (LLMs) using natural expressions
- Deploy Ballerina on Kubernetes
- Manage data persistence with bal persist
- Create your first connector with Ballerina
The Ballerina language has a built-in robust test framework, which allows you to ensure that your applications are reliable. It provides support for assertions, data providers, mocking, and code coverage features, which enable 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.balfile.public function intAdd(int a, int b) returns int { return a + b; } -
In the
main_test.balfile, make use of the test module to test out the functionality of theintAddfunction in themain.balfile.import ballerina/test; @test:Config function intAddTest() { test:assertEquals(intAdd(1, 3), 4); } -
Execute the tests using the following command.
$ bal testThen you can see the output as follows.
Compiling source user/hello_world:0.1.0 Running Tests hello_world 1 passing 0 failing 0 skipped