API Testing : Check API maintainability

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

Language: Java

Framework: Rest assured

copy
1/​/​Assuming that the API endpoints for maintainability metrics are:2/​/​ /​api/​maintainability/​bugs3/​/​ /​api/​maintainability/​technicalDebt4/​/​ /​api/​maintainability/​codeSmells56import org.junit.Test;7import static io.restassured.RestAssured.*;8import static org.hamcrest.Matchers.*;910public class MaintainabilityAPITest {11 12 @Test13 public void testBugsMetric() {14 given()15 .when()16 .get("/​api/​maintainability/​bugs")17 .then()18 .statusCode(200)19 .body("bugs", greaterThanOrEqualTo(0));20 }21 22 @Test23 public void testTechnicalDebtMetric() {24 given()25 .when()26 .get("/​api/​maintainability/​technicalDebt")27 .then()28 .statusCode(200)29 .body("technicalDebt", greaterThanOrEqualTo(0));30 }31 32 @Test33 public void testCodeSmellsMetric() {34 given()35 .when()36 .get("/​api/​maintainability/​codeSmells")37 .then()38 .statusCode(200)39 .body("codeSmells", greaterThanOrEqualTo(0));40 }41 42 /​/​Connecting to remote client with desired capabilities43 /​/​Assuming remote client has IP address 192.168.0.1 and port 444444 /​/​Assuming desired browser is Chrome45 /​/​Assuming Rest Assured is installed on remote client46 47 public void connectToRemoteClient() {48 String remoteURL = "http:/​/​192.168.0.1:4444/​wd/​hub";49 String browserName = "chrome";50 51 DesiredCapabilities capabilities = new DesiredCapabilities();52 capabilities.setBrowserName(browserName);53 54 RestAssured.baseURI = remoteURL;55 56 RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();57 58 RestAssured.given().capabilities(capabilities);59 }60 61}

Language: Javascript

copy
1const axios = require('axios');2const assert = require('assert');34/​/​Assumptions: 5/​/​1. API endpoint URL is https:/​/​example.com/​api/​maintainability6/​/​2. API maintainability resources include "page load time", "response time", and "error rate".78describe('API Maintainability Test', function(){9 it('should return the correct resources for each API maintainability metric', async function() {10 const response = await axios.get('https:/​/​example.com/​api/​maintainability');11 const responseData = response.data;12 assert.equal(response.status, 200, 'API endpoint not reachable');13 assert.ok(responseData.hasOwnProperty('pageLoadTime'), 'API response does not have pageLoadTime metric');14 assert.ok(responseData.hasOwnProperty('responseTime'), 'API response does not have responseTime metric');15 assert.ok(responseData.hasOwnProperty('errorRate'), 'API response does not have errorRate metric');16 });17});1819/​/​Code to connect to remote client with desired capabilities20/​/​Assumptions:21/​/​1. Remote client URL is "http:/​/​localhost:4444/​wd/​hub"22/​/​2. Desired capabilities include "browserName" set to "chrome"2324const webdriver = require('selenium-webdriver');25const capabilities = {26 browserName: 'chrome'27};28const driver = new webdriver.Builder()29 .usingServer('http:/​/​localhost:4444/​wd/​hub')30 .withCapabilities(capabilities)31 .build(); 3233/​/​use driver to automate API testing scenario

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