7

I have a dotnet core 3 console app project with a generated gRPC client (using the Protobuf element in the csproj below). I would like to unit test my code. Is there a way to generate my gRPC client to include interfaces for the generated classes so that I can properly mock out the gRPC client?

Thank you for your time!

<ItemGroup>
    <Protobuf Include="..\..\Data\Protos\*" GrpcServices="Client" />
</ItemGroup>
Stephen Yeager
  • 113
  • 1
  • 8

1 Answers1

4

The folks at Google decided not to include Interfaces going forward (They used to generate it one point).

The primary reason they've cited is that Interfaces can't maintain backward/forward compatibility that the underlying protobuf requires. If you change an interface, this will break the build and any compatibility with previous builds.

You can read more about it here.

As for testing the generated abstract classes, you can use a Mocking Framework such as Moq to test it out but sounds like you're already aware of that most likely. If not, there's an example here.

Francis
  • 1,798
  • 1
  • 26
  • 32
  • 1
    A bit late but this really sucks! Especially when you work with the google ads api which uses protobuf underneath. There is so much mocking code to write because every part is connected to concrete types. I just wrapped it into a large interface and mocked that instead. – Souciance Eqdam Rashti Apr 10 '22 at 19:00