API Maker
The backend engine for the AI era
Test cases in depthEpisode 63 7:32 14 chapters November 2026
The bugs that reach production hide in the paths nobody tests : a database that is busy once, a retry never run. Give Stock Check a mock that fails its call with a 503 for one call, watch the retry run and every line of it covered, answer calls with functions of the test in eight languages, and run the tests of your commit with npm run test, from your repository and in CI.
In the playlists The complete course Testing & debugging
Video thirty seven gave a custom API its first tests. This video goes further. You see mocks that fail a call like a busy database, mocks that answer a set number of calls, and mocks that compute their answer, in eight languages. And you run tests from your repository, and in CI.
The bugs that reach production hide in the paths that nobody tests. A database that times out once. A retry written months ago, and never run. A mocking library for each language, each with its own rules. And a CI job that tests what the server has, not your commit. With API Maker, a mock fails a call exactly as the API would, for as many calls as you say.
A function of the test can compute an answer, in each of the eight languages. And npm run test sends the changes of your folder first, so the code you wrote is the code that runs. In this video: a custom API with a retry, a mock that fails the call, a mock for one call only, the run, and the lines of the retry, functions as answers, conditions inside objects, every language, a test in one language for an API in another, the whole answer, npm run test from the repository, and CI.
Stock Check is a custom API of Calm Home. It gives the units of a product in the warehouses. It reads SQL Server, and adds up the quantities. When the database answers five hundred and three, busy, it logs it, and asks once more. Code like this is written once, and its second path is rarely run, until the day it is needed. Its test case has three tests. The first expects the retry: two calls, twelve units, and two attempts.
The second brings its own mock. The warehouse is busy twice, and the API must say so. The third answers with a function of the test. The first test needs mocks, and they go in the Mocks tab.
Open Test Cases. Pick Stock Check, with its three tests. Its row has a button for its mocks. There are none yet. Add a blank mock. When the test calls db dot query, with one condition, a query of the inventory, fail with an error. The warehouse is busy, with code five hundred and three, for one call. The card says that it fails. And the same mock, written as code, has error and times.
Add a second mock. db dot query again, with the same condition, the inventory, answered with two rows: seven units in one warehouse, and five in another. The first mock answers the first call, once. Then the second mock answers. Click Update.
Back on Test Cases, pick Stock Check, and Run. Three of three pass. The first test saw the database fail, then answer. It got twelve units, in two attempts, and g dot sys dot test dot calls counted two calls. Here is the coverage of the run. Every line of Stock Check ran, including the retry: the log, and the second attempt. Without a mock that fails, those lines would stay red.
Mocks are tried from the top. The first one that matches the call answers, as many times as it says. Then it is used up, and the next one answers. A mock written in the code of a test comes before the ones in the tab. And every test starts with them fresh.
A mock can also be a function. As a condition, it gets the argument of the call, and says yes or no. As an answer, it gets the arguments, and what it returns is the answer. What it throws fails the call, like an API would. In TypeScript, it can be async.
A condition that is an object asks for what that object has, inside objects too. This one matches a query of the inventory whose find has this product, whatever else the query asks for: a sort, a limit, or other filters. A list asks for as many items. And a key set to null asks for no value at all.
Here are the same mocks in Python, with error, times, and a lambda. In Go, it is a func. In C sharp, it is Mock dot Answer. In Rust, it is answers, with a closure. Java and Kotlin have answers and whenMatches, and PHP has an arrow function. Eight languages, and one set of rules.
A test in one language can run a custom API written in another. Here, a test in Python runs an API written in Go. The API runs in the Go sandbox, and calls db dot query. API Maker finds the mock, and asks the test for its function, in Python, while the API waits. The answer goes back to Go. The API never knows it was a test.
A call that asks for the whole answer gets it whole from a mock too. A mock that fails gives success false, the status, and the errors, and nothing is thrown. So the code that reads the status is tested as well.
The tests are files in the Git repository, next to the code they test. Change one in your editor, and run npm run test. It sends the changes of the folder to the server first. It waits until the server has saved them. Then the run starts, and every step prints as it happens. The code you wrote is the code that ran. When npm run start already runs in the folder, it keeps the folder in sync, and npm run test starts the run at once.
With no sync, it runs what the server has. A filter runs only the test cases it names, bail stops at the first failure, and json writes the whole result to a file.
In CI, there is no config file. The job gives three variables: the address of the server, the sync token as a secret, and the account. A fresh clone never synced, so push sends the code of the commit to the server first. So the tests of the commit run against the code of the commit. The exit code is zero when everything passed, one when a test failed, and two when the run did not finish.
And the coverage, in lcov, is ready for a coverage service. Point the job at a server for development or tests, never at production.
Mocks can fail a call, like the API would. Mocks can answer a set number of calls, to test a retry. Functions work as conditions and answers, in all eight languages. Conditions can look inside objects. And npm run test runs from your repository, and in CI. Next: debugging, from a failing call to the line. API Maker. Build faster, spend smarter, deliver better.
Length 9:10Debugging
Length 6:46Coverage
Length 5:58Debugging
Length 6:28API Testing