GithubHelp home page GithubHelp logo

testerina's Introduction

Testerina

This repository is no longer used for development. Current developments are done in following repository.

https://github.com/ballerina-lang/ballerina

Testerina is the test framework built for the Ballerina language. This will be a part of ballerina-tools-<release-version>.zip distribution [1].

Testerina provides ballerina test command.

Once you run tests using ballerina test command, Testerina will print a summary of test results on the console.

To test a file written in Ballerina language, use the test command as follows.
./ballerina test <package_name>

Testerina provides following functions.

package ballerina.test;

  • startService(string servicename)
  • assertTrue(boolean condition, string message)
  • assertFalse(boolean condition, string message)
  • assertStringEquals(string actual, string expected, string errorMessage)
  • assertIntEquals(int actual, int expected, string errorMessage)
  • assertFloatEquals(float actual, float expected, string errorMessage)
  • assertBooleanEquals(boolean actual, boolean expected, string errorMessage)
  • assertStringArrayEquals(string[] actual, string[] expected, string errorMessage)
  • assertFloatArrayEquals(float[] actual, float[] expected, string errorMessage)
  • assertIntArrayEquals(int[] actual, int[] expected, string errorMessage)
  • assertFail(string errorMessage)
  • createBallerinaError (string errorMessage, string category) (AssertError)

Writing ballerina tests

  • Test files should contain _test.bal suffix.
  • Test functions should contain test prefix.
    e.g.: testAddTwoNumbers()
  • Each test function may contain one or more asserts.
    e.g. 1:
import ballerina.test;
function testAddTwoNumbers() {
    test:assertIntEquals(addTwoNumbers(1, 2), 3, "Number addition failed for positive numbers");
    test:assertIntEquals(addTwoNumbers(-1, -2), -3, "Number addition failed for negative numbers");
    test:assertIntEquals(addTwoNumbers(0, 0), 0, "Number addition failed for number zero");
}

If at least one assert fails, whole test function will be marked as failed. Detailed information is shown in the test result summary.

One package may contain more than one *._test.bal file.

Tutorial

1 Download [1] ballerina-tools-<release-version>.zip distribution and unzip.
2 Unzip and go to ballerina-tools-<release-version>.
3 Create a directory samples/foo/bar.
4 Create the following two files inside this directory.

e.g.: sample.bal

package samples.foo.bar;

function main (string[] args) {
    int i = intAdd(1, 2);
    println("Result: " + i);
}
 
function intAdd(int a, int b) (int) {
    return a + b;
}

e.g.: sample_test.bal

package samples.foo.bar;
 
import ballerina.test;
 
function testInt() {	
    int answer = 0;
    answer = intAdd(1, 2);
    test:assertIntEquals(answer, 3, "IntAdd function failed");
	
}

Note the package hierarchy in above files.

5 Run tests using following command.
> ./bin/ballerina test samples/foo/bar/

Following is a sample console output.

result: 
tests run: 1, passed: 1, failed: 0

Reference:

[1] https://github.com/ballerinalang/distribution

testerina's People

Contributors

akalankapagoda avatar anupama-pathirage avatar ballerina-bot avatar chanakaudaya avatar chanukaranaba avatar djkevincr avatar hasithaa avatar hemikak avatar kasunbg avatar lafernando avatar lankavitharana avatar maheshika avatar manuranga avatar manuri avatar nadeeshaan avatar nirodha avatar pubudu91 avatar sameerajayasoma avatar shafreenanfar avatar shan1024 avatar suhand avatar supuns avatar wso2-jenkins-bot avatar yasassri avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.