You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The generated test code for the ballerina service template(bal new -t service myService) can be improved
Describe your problem(s)
The generated test code looks like this:
importballerina/http;
importballerina/io;
importballerina/test;
http:ClienttestClient=checknew ("http://localhost:9090");
// Before Suite Function
@test:BeforeSuitefunction beforeSuiteFunc() {
io:println("I'm the before suite function!");
}
// Test function
@test:Config {}
function testServiceWithProperName() {
string|error response =testClient->get("/greeting/?name=John");
test:assertEquals(response, "Hello, John");
}
// Negative test function
@test:Config {}
function testServiceWithEmptyName() returnserror? {
http:Responseresponse=checktestClient->get("/greeting/");
test:assertEquals(response.statusCode, 500);
json errorPayload =checkresponse.getJsonPayload();
test:assertEquals(errorPayload.message, "name should not be empty!");
}
// After Suite Function
@test:AfterSuitefunction afterSuiteFunc() {
io:println("I'm the after suite function!");
}
Describe your solution(s)
The code can be improved by utilising the client resource methods:
importballerina/http;
importballerina/io;
importballerina/test;
http:ClienttestClient=checknew ("http://localhost:9090");
// Before Suite Function
@test:BeforeSuitefunction beforeSuiteFunc() {
io:println("I'm the before suite function!");
}
// Test function
@test:Config {}
function testServiceWithProperName() {
string|error response =testClient->/greeting(name="John");
test:assertEquals(response, "Hello, John");
}
// Negative test function
@test:Config {}
function testServiceWithEmptyName() returnserror? {
http:Responseresponse=checktestClient->/greeting;
test:assertEquals(response.statusCode, 500);
json errorPayload =checkresponse.getJsonPayload();
test:assertEquals(errorPayload.message, "name should not be empty!");
}
// After Suite Function
@test:AfterSuitefunction afterSuiteFunc() {
io:println("I'm the after suite function!");
}
Related area
-> Other Area
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
The text was updated successfully, but these errors were encountered:
Description
The generated test code for the ballerina service template(
bal new -t service myService
) can be improvedDescribe your problem(s)
The generated test code looks like this:
Describe your solution(s)
The code can be improved by utilising the client resource methods:
Related area
-> Other Area
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response
The text was updated successfully, but these errors were encountered: