I'm currently scratching my and my colleagues head about whether and how we could test SyncService::syncFoo
in any meaningful way
that does not involve basically recreating the whole call tree as mocks.
Edit: It is not a microservice its a Service Class within one project - there was some confusion in the answers/comments
We could Mock all three dependencies and make sure the right Message is passed to the Queue but that seems useless as we would reflect the implementation 1:1 in the test. The example code is a bit stripped down but it represents what we want to achieve very nicely.
Should we use a completely different approach? Is it ok to NOT test the sync service?
// this should be the signature we want to call
SyncService.syncFoo(Entity)
we now want to:
- Get a list of endpoints our message should be delivered to based on the passed entity
- create a message based on the passed entity
- dispatch the message using the queue
Our current basic approach:
Class MsgQueue
{
// tested
public dispatch(msg, endpoints[])
}
Class MsgFactory
{
// tested
create(Entity)
}
Class EndpointRepository()
{
// tested
getEndpoints(Entity)
}
Class SyncService()
{
MsgQueue
MsgFactory
EndpointRepository
public sync(Entity)
{
endPoints = this.EndpointRepository.getEndPoints(Entity)
if endPoints.empty()
{
return
}
msg = this.MsgFactory.create(Entity)
this.MsgQueue.dispatch(msg, endPoints)
}
}