
Facilitates HTTP client testing by simulating network responses and scenarios, allowing customization of request handling and verification of client behavior under various conditions.
Mock Engine is a powerful tool for mocking Ktorfit API responses in your Kotlin Multiplatform projects. It uses KSP (Kotlin Symbol Processing) to generate mock implementations of your Ktorfit APIs, making it easy to test your application without relying on a live server.
Mock Engine works by processing annotations on your Ktorfit API interfaces. When you annotate a Ktorfit method with @Mock, Mock Engine generates a mock implementation of that method that returns data from a specified JSON file.
Here's an example of how to use Mock Engine to mock a Ktorfit API:
// In your Ktorfit API interface
interface SampleApi {
@Mock(files = ["mock/sample-mock.json"])
@GET("sample-url/{customPath}")
suspend fun sampleRequest(@Path("customPath") customPath: String): SampleModel
}In this example, the @Mock annotation tells Mock Engine to generate a mock implementation of the sampleRequest method that returns data from the mock/sample-mock.json file.
@Mock to generate mock implementations.To get started with Mock Engine, you'll need to add the following plugin and dependencies to your project:
build.gradle.kts
plugins {
id("com.google.devtools.ksp")
id("io.github.pedro-bachiega.mock-engine") version "<version>"
}
dependencies {
// Ktorfit
implementation("de.jensklingenberg.ktorfit:ktorfit-lib:<version>")
// Mock Engine
implementation("com.pedrobneto.mock.engine:client:<version>")
implementation("com.pedrobneto.mock.engine:annotation:<version>")
}Once you've added the plugin and dependencies, you can start annotating your Ktorfit API methods with @Mock.
Mock Engine is an open-source project, and we welcome contributions from the community. If you'd like to contribute, please fork the repository and submit a pull request.
Mock Engine is a powerful tool for mocking Ktorfit API responses in your Kotlin Multiplatform projects. It uses KSP (Kotlin Symbol Processing) to generate mock implementations of your Ktorfit APIs, making it easy to test your application without relying on a live server.
Mock Engine works by processing annotations on your Ktorfit API interfaces. When you annotate a Ktorfit method with @Mock, Mock Engine generates a mock implementation of that method that returns data from a specified JSON file.
Here's an example of how to use Mock Engine to mock a Ktorfit API:
// In your Ktorfit API interface
interface SampleApi {
@Mock(files = ["mock/sample-mock.json"])
@GET("sample-url/{customPath}")
suspend fun sampleRequest(@Path("customPath") customPath: String): SampleModel
}In this example, the @Mock annotation tells Mock Engine to generate a mock implementation of the sampleRequest method that returns data from the mock/sample-mock.json file.
@Mock to generate mock implementations.To get started with Mock Engine, you'll need to add the following plugin and dependencies to your project:
build.gradle.kts
plugins {
id("com.google.devtools.ksp")
id("io.github.pedro-bachiega.mock-engine") version "<version>"
}
dependencies {
// Ktorfit
implementation("de.jensklingenberg.ktorfit:ktorfit-lib:<version>")
// Mock Engine
implementation("com.pedrobneto.mock.engine:client:<version>")
implementation("com.pedrobneto.mock.engine:annotation:<version>")
}Once you've added the plugin and dependencies, you can start annotating your Ktorfit API methods with @Mock.
Mock Engine is an open-source project, and we welcome contributions from the community. If you'd like to contribute, please fork the repository and submit a pull request.