What is the recommended way to inject a mock service for unit testing? #1307
-
I am working on a service that needs to be provided by a mock class for unit testing and by a production service when running in production mode. So I need to inject that mock class for testing cases but inject the real class for production. My plan is to define the service in the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I actually don't believe we had the need to mock something in our languages yet. So no general recommendations. However, what I would probably do is add my to-be-mocked services to the dependency injection module context. See this, that we use for Langium by default. That way you could decide what and how to mock on the caller side instead of needing to build multiple different modules. |
Beta Was this translation helpful? Give feedback.
I actually don't believe we had the need to mock something in our languages yet. So no general recommendations. However, what I would probably do is add my to-be-mocked services to the dependency injection module context. See this, that we use for Langium by default. That way you could decide what and how to mock on the caller side instead of needing to build multiple different modules.