Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the test documentation #8966

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 11 additions & 13 deletions swan-lake/by-example/testerina-assertions/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Link from "next/link";
export const codeSnippetData = [
`import ballerina/test;

@test:Config { }
@test:Config
function testAssertEquals() {
json a = {name:"John Doe", age:25, address:{city:"Colombo",
country:"Sri Lanka"}};
Expand All @@ -17,29 +17,29 @@ function testAssertEquals() {
test:assertEquals(a, b, msg = "JSON values are not equal");
}

@test:Config { }
@test:Config
function testAssertNotEquals() {
string s1 = "abc";
string s2 = "def";
// Asserts two values for value inequality using \`assertNotEquals\`.
test:assertNotEquals(s1, s2, msg = "String values are equal");
}

@test:Config { }
@test:Config
function testAssertTrue() {
boolean value = true;
// Asserts if the provided value is \`true\`.
test:assertTrue(value, msg = "AssertTrue failed");
}

@test:Config { }
@test:Config
function testAssertFalse() {
boolean value = false;
// Asserts if the provided value is \`false\`.
test:assertFalse(value, msg = "AssertFalse failed");
}

@test:Config { }
@test:Config
function testAssertFail() {
boolean flag = true;
if (flag) {
Expand All @@ -57,7 +57,7 @@ class Person {
string address = "No 20, Palm grove";
}

@test:Config { }
@test:Config
function testAssertExactEquals() {
Person person1 = new;
Person person2 = person1;
Expand All @@ -66,7 +66,7 @@ function testAssertExactEquals() {
msg = "Objects are not exactly equal");
}

@test:Config { }
@test:Config
function testAssertNotExactEquals() {
Person person1 = new;
Person person2 = new;
Expand Down Expand Up @@ -284,9 +284,8 @@ export function TesterinaAssertions({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -330,9 +329,8 @@ export function TesterinaAssertions({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function afterEachFunc() {
}

// A test function.
@test:Config { }
@test:Config
function testFunction1() {
io:println("I'm in test function 1!");
test:assertTrue(true, msg = "Failed!");
}

// Another test function.
@test:Config { }
@test:Config
function testFunction2() {
io:println("I'm in test function 2!");
test:assertTrue(true, msg = "Failed!");
Expand Down Expand Up @@ -246,9 +246,8 @@ export function TesterinaBeforeAndAfterEach({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -292,9 +291,8 @@ export function TesterinaBeforeAndAfterEach({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function testFunction1() {
}

// Another test function.
@test:Config {}
@test:Config
function testFunction2() {
io:println("I'm in test function 2!");
test:assertTrue(true, msg = "Failed!");
Expand Down Expand Up @@ -244,9 +244,8 @@ export function TesterinaBeforeAndAfterGroups({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -290,9 +289,8 @@ export function TesterinaBeforeAndAfterGroups({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ function beforeSuit() {
}

// A Test function.
@test:Config { }
@test:Config
function testFunction1() {
io:println("I'm in test function 1!");
test:assertTrue(true, msg = "Failed");
}

// A Test function.
@test:Config { }
@test:Config
function testFunction2() {
io:println("I'm in test function 2!");
test:assertTrue(true, msg = "Failed");
}

// Executed after all the test functions in the module.
@test:AfterSuite { }
@test:AfterSuite
function afterSuite() {
io:println("I'm the after suite function!");
}
Expand Down Expand Up @@ -248,9 +248,8 @@ export function TesterinaBeforeAndAfterSuite({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -294,9 +293,8 @@ export function TesterinaBeforeAndAfterSuite({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down
12 changes: 5 additions & 7 deletions swan-lake/by-example/testerina-group-tests/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function testFunction2() {
}

// Does not belong to any test group.
@test:Config { }
@test:Config
function testFunction3() {
io:println("I'm the ungrouped test");
test:assertTrue(true, msg = "Failed!");
Expand Down Expand Up @@ -424,9 +424,8 @@ export function TesterinaGroupTests({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -470,9 +469,8 @@ export function TesterinaGroupTests({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function testFunction2() {

// This will be executed without depending on other functions.
// However, since other functions depend on this function, it will be executed first.
@test:Config { }
@test:Config
function testFunction3() {
io:println("I'm in test function 3!");
test:assertTrue(true, msg = "Failed!");
Expand Down Expand Up @@ -244,9 +244,8 @@ export function TesterinaGuaranteeTestExecutionOrder({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -290,9 +289,8 @@ export function TesterinaGuaranteeTestExecutionOrder({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down
14 changes: 6 additions & 8 deletions swan-lake/by-example/testerina-mocking-functions/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ballerina/io;
@test:Mock { functionName: "intAdd" }
test:MockFunction intAddMockFn = new();

@test:Config {}
@test:Config
function testReturn() {
// Stubs the calls to return a specific value.
test:when(intAddMockFn).thenReturn(20);
Expand Down Expand Up @@ -52,7 +52,7 @@ public function mockPrint(any|error... val) {
tally = tally + 1;
}

@test:Config {}
@test:Config
function testCall() {
// Stubs the calls to the \`io:println\` function
// to invoke the \`mockPrint\` function instead.
Expand Down Expand Up @@ -362,9 +362,8 @@ export function TesterinaMockingFunctions({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -408,9 +407,8 @@ export function TesterinaMockingFunctions({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down
22 changes: 10 additions & 12 deletions swan-lake/by-example/testerina-mocking-objects/content.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public client class MockHttpClient {
}
}

@test:Config { }
@test:Config
function testTestDouble() {
// Creates and assigns the defined test-double.
clientEndpoint = test:mock(http:Client, new MockHttpClient());
http:Response res = performGet();
test:assertEquals(res.statusCode, 500);
}

@test:Config { }
@test:Config
function testReturn() {
// Creates and assigns a default mock object,
// which subsequently needs to be stubbed.
Expand All @@ -90,7 +90,7 @@ function testReturn() {
test:assertEquals(res.statusCode, 200);
}

@test:Config { }
@test:Config
function testReturnSequence() {
http:Response mockResponse = new;
mockResponse.statusCode = 404;
Expand All @@ -105,7 +105,7 @@ function testReturnSequence() {
test:assertEquals(res.statusCode, 404);
}

@test:Config { }
@test:Config
function testReturnWithArgs() {
http:Response mockResponse = new;
mockResponse.statusCode = 404;
Expand All @@ -121,7 +121,7 @@ function testReturnWithArgs() {
test:assertEquals(res.statusCode, 404);
}

@test:Config { }
@test:Config
function testSendNotification() {
smtpClient = test:mock(email:SmtpClient);
// Stubs the \`send\` method of the \`mockSmtpClient\` to do nothing.
Expand All @@ -132,7 +132,7 @@ function testSendNotification() {
test:assertEquals(err, ());
}

@test:Config {}
@test:Config
function testMemberVariable() {
string mockId = "test";
lock {
Expand Down Expand Up @@ -478,9 +478,8 @@ export function TesterinaMockingObjects({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[0] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([true, false])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down Expand Up @@ -524,9 +523,8 @@ export function TesterinaMockingObjects({ codeSnippets }) {
width="20"
height="20"
fill="#3ad1ca"
className={`${
btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
className={`${btnHover[1] ? "btnArrowHover" : "btnArrow"
} bi bi-arrow-right`}
viewBox="0 0 16 16"
onMouseEnter={() => updateBtnHover([false, true])}
onMouseOut={() => updateBtnHover([false, false])}
Expand Down