API Testing : Check API scalability

Verify that the API correctly handles API scalability and returns the correct resources for each API scalability metric.

Language: Java

Framework: Rest assured

copy
1/​/​Assumptions: 2/​/​1. The API is already deployed and available for testing. 3/​/​2. The scalability metrics have been defined and documented. 4/​/​3. The API output for each scalability metric is also available for reference. 56import org.testng.annotations.Test;7import io.restassured.response.Response;8import io.restassured.RestAssured;9import static io.restassured.RestAssured.given;10import static org.testng.Assert.assertEquals;1112public class APITest {1314@Test15public void testAPIScalability() {1617/​/​Assuming the API endpoint for scalability metrics is https:/​/​api.scalability.com1819RestAssured.baseURI = "https:/​/​api.scalability.com";2021/​/​Assuming there are multiple scalability metrics available to test and the first metric is "Number of concurrent users"22Response response = given()23.header("Content-Type", "application/​json")24.queryParam("scability-metric", "concurrent-users")25.get();2627/​/​Asserting that the API returns a status code of 20028assertEquals(response.getStatusCode(), 200);2930/​/​Asserting that the API returns the expected output for the first scalability metric, which is the number of concurrent users31assertEquals(response.getBody().asString(), "1000");3233/​/​Assuming there are more metrics to test and we can add more assertions as necessary3435/​/​Connecting to a remote client with desired capabilities36/​/​Assuming the remote client has set the "platform" capability to "Windows 10" and the "browser" capability to "Chrome"37/​/​DesiredCapabilities capabilities = new DesiredCapabilities();38/​/​capabilities.setCapability("platform", "Windows 10");39/​/​capabilities.setCapability("browser", "Chrome");40/​/​RemoteWebDriver driver = new RemoteWebDriver(new URL(remoteUrl), capabilities);41/​/​RestAssured.defaultParser = new Parser("application/​json;charset=UTF-8");42}43}

Language: Javascript

copy
1/​/​ Mocha and Chai.23/​/​Assumptions: 4/​/​1. API endpoint that returns resources for a given API scalability metric.5/​/​2. API soft limit is set at 10,000 resources.6/​/​3. API hard limit is set at 100,000 resources.78const chai = require('chai');9const chaiHttp = require('chai-http');10const expect = chai.expect;1112chai.use(chaiHttp);1314describe('API Scalability', function() {15 it('Should handle API scalability and return correct resources for each API scalability metric', function(done) {16 17 /​/​Assuming API endpoint is /​api/​v1/​metrics and metric parameter can be set as a query parameter18 /​/​Assuming metric parameter has values between 1 to 10, with each value representing a different scalability metric.19 /​/​Assuming the API returns an array of resources.2021 /​/​Soft limit test - Query for metric 1 and expect less than or equal to 10,000 resources22 chai.request('http:/​/​localhost:3000')23 .get('/​api/​v1/​metrics?metric=1')24 .end(function(err, res) {25 expect(err).to.be.null;26 expect(res).to.have.status(200);27 expect(res.body).to.be.an('array');28 expect(res.body.length).to.be.at.most(10000);29 done();30 });3132 /​/​Hard limit test - Query for metric 10 and expect less than or equal to 100,000 resources33 chai.request('http:/​/​localhost:3000')34 .get('/​api/​v1/​metrics?metric=10')35 .end(function(err, res) {36 expect(err).to.be.null;37 expect(res).to.have.status(200);38 expect(res.body).to.be.an('array');39 expect(res.body.length).to.be.at.most(100000);40 done();41 });4243 /​/​Connect to remote client with desired capabilities44 /​/​Assuming remote webdriver client configuration is on remotehost with port 444445 var webdriver = require('selenium-webdriver');46 var remoteCapabilities = webdriver.Capabilities.chrome();47 var remoteDriver = new webdriver.Builder().48 usingServer('http:/​/​remotehost:4444/​wd/​hub').49 withCapabilities(remoteCapabilities).50 build();51 });52});

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing