2

I recently came across a blog post (https://testing.googleblog.com/) discussing the use of fake objects over mocking for testing purposes. The post detailed creating fake objects for necessary dependencies, such as Repositories and Factories, with fixed return values and then injecting these fakes via constructors for tests. This approach seemed beneficial to me despite the increase in code volume when applied within the same package.

However, I'm currently working on a service 'A' that is structured as a multi-module project, relying on modules 'C', 'D', and 'E'. When attempting to test a System Under Test (SUT) named 'foo' that imports these modules, I faced a challenge. Creating separate fake objects for each test led to concerns about code duplication, especially if other services implement functionality that references these modules. This situation made me consider whether it might be necessary to create test modules specifically for providing these fake objects to avoid duplication across module boundaries.

Given this context, I have two main questions

  1. Is it common practice to create test modules in a multi-module environment and provide fake objects to maintain testability without duplicating code?

  2. in a dynamic query situation using QueryDL, in what way is it recommended to create fake objects?

Are there alternative strategies for handling dependencies in such scenarios that might be more efficient or effective? I'm looking for insights or experiences from others who have navigated similar challenges in their projects.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.