Skip to content

Instantly share code, notes, and snippets.

@yasassri
Created June 4, 2018 08:12
Show Gist options
  • Save yasassri/a68a1c6730644832cd05689757faa5e2 to your computer and use it in GitHub Desktop.
Save yasassri/a68a1c6730644832cd05689757faa5e2 to your computer and use it in GitHub Desktop.
import ballerina/test;
import ballerina/io;
any[] outputs = [];
int counter = 0;
// This is the mock function which will replace the real function
@test:Mock {
packageName: "ballerina.io",
functionName: "println"
}
public function mockPrint(any... s) {
outputs[counter] = s[0];
counter++;
}
@test:Config
function testFunc() {
// Invoking the main function
main();
test:assertEquals("Hello, World!", outputs[0]);
}
// The main function
function main(string... args) {
io:println("Hello, World!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment