1

I have built a Springboot application which has a gRPC server as one of its dependencies. While running the integration test, I am able to use embedded Kafka, embedd MySQL etc using TestContainers, but how can I create an embedded gRPC server while running my integration test suite?

I have the .proto contract definition file. I would use Wiremock to mock the request and responses to the gRPC server, but I am unable to start the embedded gRPC server yet.

It will be really great if I could find some help here.

Come to think of it, my question can be generalized to starting a generic embedded HTTP server in Springboot integration test, using TestContainers or otherwise.

Rajan Prasad
  • 1,582
  • 1
  • 16
  • 33
  • 1
    Would this be useful https://stackoverflow.com/questions/31938242/using-spring-boot-together-with-grpc-and-protobuf ? – San P Mar 06 '20 at 06:16
  • The two repos shared there are worth looking into. However, it seems to me that they are not talking about using a gRPC server in an integration test environment. I myself figured out how to set up a mocked gRPC server for integration testing, which I will provide as an answer to this question. – Rajan Prasad Mar 08 '20 at 18:08

1 Answers1

1

I had a similar problem with IT testing Java gRPC service integrations, as using InProcessServer is quite cumbersome and quite hard to use when you need to return different responses for different tests. Also when using it you cannot really test your Stub beans and their configuration, since you can't pass InProcessServer host as a variable.

For this purpose I've created a gRPC Java mocking tool gRPC Mock. It has two integration modules - one for spring-boot and one for JUnit5. It follows a similar DSL type of structure to HTTP mocking service WireMock for creating the stubs. You can visit the GitHub page for some examples.

Fadel
  • 33
  • 1
  • 7