How do you write unit tests in Scala, and how do you use the mocking technique?
Briefly

When a service is called directly inside a function, it creates tight coupling, thereby complicating unit testing, which necessitates code refactor to enable testing.
Mocking functions within the same class poses challenges due to tight coupling, hence employing spying or partial mocks can help mock specific methods effectively.
Mocking or partially mocking a singleton object in Scala is significantly harder than in a regular class because of its tightly coupled nature, making testing more difficult.
To facilitate easier testing, services should be made replaceable through dependency injection or mocks, allowing flexibility in unit testing scenarios.
Read at Medium
[
]
[
|
]