Introducing Mockoon: easy API mocking tool
Have you tried Mockoon to capture and mock real API responses?
.net core - Mocking API Calls for Unit Tests with Mockoon and Nunit - Stack Overflow
mocking - Recording external API using mockoon - Stack Overflow
Videos
» npm install @mockoon/cli
It's a bit of a broad question for SO I think. But here are some thoughts. In my opinion, pure unit testing should mock APIs programmatically and not depend on external applications like Mockoon.
What you want to do seems to be more like integration testing, where your code is calling an external API, except that instead of maintaining an instance of the original API specifically for test/QA purposes, you maintain a mock (with Mockoon).
Then, the general idea is more or less the following:
- you prepare the mock API with Mockoon locally with the UI.
- you save Mockoon's data file in the repository.
- During the GitHub Actions workflow, you install Mockoon CLI and start it targeting the data file (relevant tutorial).
- You run your application tests and modify the environment variable containing the API URL to point to were the CLI is running (probably something like
http://localhost:3000).
Good answer by Guilaume. I have couple things to point out for the first step:
- Don't forget that you have to press PLAY for the particular "routes" to start listening for incoming requests:

- You have to configure the request and especially the response Headers or you might run into trouble
- Instead of running Github Actions I have opted to use TestContainers
- At the time of writing there is no specific Mockoon TestContainer module
- I managed to configure a GenericTestContainer to run Mockoon; it was a bit of a schlepp as I am on a Springboot/Kotlin project but it would apply to a Java project just as equally but I managed it
- I think Mockoon should have an area where bleeding edge solutions like the above can be shared on the Mockoon site (just a thought)
[Update 2023-11-20] Since version 3.1.0 a recording mode has been added.
There is no "automatic" recording option in Mockoon. But you can enable the proxy and from the "Logs" tab add the endpoints manually.
- Enable the proxy:

- Manually mock an request/response:

According to this github issue, unfortunately the author is not interested in implementing this:
https://github.com/mockoon/mockoon/issues/21
I was looking to do the same, but now I'm evaluating polly.js