java-sdk icon indicating copy to clipboard operation
java-sdk copied to clipboard

Provide MockDaprClient or MockActorClient for easy unit/integration testing

Open javageek79 opened this issue 3 years ago • 4 comments

Describe the proposal

For making unit testing and integration testing easier, it would be great, if dapr java sdk could ship with ready configured or easy configurable mock implementations for generally used items like DaprClient or ActorClient.

For ActorClient in particular, it would also be great, if the protocol http/gRpc could be configured during tests so it would be easier to use an in memory mock http webserver instead of gRPC.

javageek79 avatar May 10 '21 16:05 javageek79

Will other SDK be supported? .NET in particular?

leonids2005 avatar Aug 16 '21 12:08 leonids2005

@leonids2005 Consider creating an issue in dapr/dotnet-sdk for tracking a similar feature if you're interested, I believe these requests are being tracked on a per SDK basis as they have different maintainers.

CodeMonkeyLeet avatar Aug 17 '21 00:08 CodeMonkeyLeet

These issues are per SDK based on what is idiomatic per language. @leonids2005 Please, create an issue in the .Net SDK is you think there is a need for the same there.

artursouza avatar Aug 20 '21 23:08 artursouza

Hi @javageek79 ,

I have created a pull request to address your ask to make mocking easier for ActorClient. See PR how it can be used: https://github.com/dapr/java-sdk/pull/606/commits/4a47177005f7e93758f2f7f7d95c0db0f50e9876#diff-e59f8f865998bb2c375fe9e23fd64df4fb3b0c9b2b89e0e5926cbcb423e19b2a

The actor’s DaprClient interface does not need to be mocked since ActorClient should be the only class offering connectivity to Actors for the app and DaprClient is hidden from the app.

I also did not find a need to create a mocking class for the non-actor DaprClient interface since it is already an interface – which should be easy to mock already.

Please, let me know what you think.

Thanks, Artur Souza

artursouza avatar Aug 21 '21 01:08 artursouza