#Unable to write test case for class which has multiple service call

1 messages · Page 1 of 1 (latest)

crisp trellis
#

I have FileHandler Class which has some data base service call , now when i have mock the database service then ideally where there is db servcie call it should return the mocked database service only . but giving some error

@test:Config{}
function testProcessFile() {
FileHandler filehandler = check new ;
filehandler.dbSrevice = new MockDbService();
}

But givng error at line new MockDbServuce saying incompatible issue as FileHandler class is expecting orginal Dbservice class instead of MockDbService.

How to relsove such cases..
Helpful if i could get the example similar to to that how to handle such scenario

topaz drift
#

Not sure if i understand you correctly but this sounds like you have two different types?

I assume you would want to „““mock““ the behavior of a this „dbservice“ but it should still be of type dbservice just with a mock implementation if that makes sense?

#

But i haven’t really used the unit test suite too extensively

#

Not ballerina related but im personally not a huge fan of mocking behavior anyway. With tools like testcontainer etc i dont really feel like i need it a lot.

#

I rather just spin up a real db while testing otherwise you also need test code for your mock code (;; but just different mindsets