Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How manage working with multiple microservices and mocking them in a development (not test) environment?

I'm using Spring Boot 1.5.9 and we have a micro service that connects with another micro services.

For integration test and development (the developer computer) I would like to mock/stub the rest calls made for another micro services. For unit/integration tests this question is already answered many times: WireMock, MockBean and MockRestServiceServer are good tools. But for development I'm trying to figure out the best approach.

Why? Is a problem to start each microservice that the actual microservice depends. So the idea is make the microservice independent and start without any additional server running in the developer's machine or on other place. So, a simple `mvn spring-boot run' would be enough to start my microservice and work without any concern about another microservices.

So, my question is: what the recommended aproach for mock/stub rest calls in development? Wiremock is a good approach in this case too?

My project

I have two profiles in src/main/java/resources/: the 'default' (application.properties, that's used for another environment) and the 'dev' (application-dev.properties, used for development).

In my tests (src/test/java/resources/) I have only one application.properties, that is basic a copy of application-dev.properties.

I already try to use Wiremock for integration tests and works well. But I would not like to use it for development too because I don't like so much the idea to introduce a dependency only used for development in my JAR. My intention is use the same strategy to integration test and development.

So, what's the options?

like image 331
Dherik Avatar asked Dec 27 '17 13:12

Dherik


1 Answers

So you want to start your microservice locally e.g. for manual testing, but you do not want to start all the other microservices it depends on.

Teams do one of the following:

  • Connect local microservice to shared, deployed microservice instances (staging environments)
  • Connect local microservice to easy-to-launch docker images of the other microservices
  • Connect to a single locally running wiremock instance that mimics some/all the other microservices. You can start wiremock standalone for that, separately from your microservice
  • Write a minimal lightweight custom mock of other microservices (only better than wiremock if has to do some business logic)
  • Do not connect to anything, but return dummy values from the internal API client.
  • Actually start all other microservices locally

Which of those works best for you depends on your environment, and what exactly the other microserivce dependencies provides as functionality. You cannot expect any of those to be a silver bullet that is best for all teams and all situations.

like image 104
tkruse Avatar answered Oct 01 '22 08:10

tkruse