Test Classes
Using generative tools like ChatGPT to generate test classes for web apps
Summary
Example: Creating test classes for a modern app using generative AI
Prompt
Create a test class for the Bicycle Rental web app that tests the functionality of the search feature using Axios and MongoDB.Response
const assert = require("assert");
const axios = require("axios");
const mongodb = require("mongodb");
describe("Search feature", () => {
let db;
let client;
before(async () => {
client = await mongodb.connect("mongodb://localhost:27017");
db = client.db("bicycle-rental");
});
after(async () => {
await client.close();
});
it("should return results when given a valid search term", async () => {
const response = await axios.get("http://localhost:3000/api/search?q=road");
assert(response.status === 200);
assert(response.data.length > 0);
});
it("should return an empty array when given an invalid search term", async () => {
const response = await axios.get("http://localhost:3000/api/search?q=invalid");
assert(response.status === 200);
assert(response.data.length === 0);
});
});Discussion
Last updated