You can use Testerina for this purpose which is the test framework written for Ballerina language. This is shipped by default in ballerina tools distribution.
http://ballerinalang.org/downloads/
Writing Test File
Write your test cases as follows in a different file say sample_test.bal
package samples.foo.bar;
import ballerina.test;
function testAddTwoNumbers() {
test:assertEquals(addTwoNumbers(1,2), 3, "Positive number addition failed");
}
Running tests with Ballerina test
command.
./bin/ballerina test <package_path>
Note that this file is located in the same package as your sample.bal
file, i.e. ../samples/foo/bar
.
You can invoke your test cases as follows. Assuming you are using ballerina tools distribution 0.8.0
and sample.bal, sample_test.bal
files are located in ballerina-tools-0.8.0/samples/foo/bar
,
./bin/ballerina test samples/foo/bar/
You will get an output as follows as per version 0.8.0
.
result:
tests run: 1, passed: 1, failed: 0
For more available native test functions, please refer Ballerina API Documentation.