Skip to content

Instantly share code, notes, and snippets.

@mbjelac
Last active November 10, 2023 10:29
Show Gist options
  • Save mbjelac/b30f68c2cb17376a095c33e061a71189 to your computer and use it in GitHub Desktop.
Save mbjelac/b30f68c2cb17376a095c33e061a71189 to your computer and use it in GitHub Desktop.
API test service config
// imports...
@Configuration // for Spring's DI setup
class ApiTestDoubles(
private val factory: ApiTestDoubleFactory
) {
// 👇 one for each top-level service
@Bean // this method's return value will be in the DI context for others to use
fun users(): Users = factory
.createTestDouble(Users::class.java) // specify service class
.withMethod("create-user") { it.createUser(any()) } // define label for method
.withMethod("get-users") { it.getUsers(any()) } // define label for another method
.build() // build a test-double to use instead of 'Users' service
}
@mbjelac
Copy link
Author

mbjelac commented Nov 9, 2023

The "labels" are attached to methods so we can stub or spy from the frontend.

@mbjelac
Copy link
Author

mbjelac commented Nov 10, 2023

Originally published as part of this article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment