Lester Gray
Lester Gray

Reputation: 327

Using Karate to build a component test for an API that contains a DAO?

I'm learning to use Karate to develop automation testing for a Java based API which contains a DAO layer to talks to a database to retrieve some information and present back to the callee. This is the simplistic workflow :

GET payments-information -> Calls PaymentsInformationService -> Calls a PaymentInformationDAO -> Calls a MYSQL Database -> Returns 200OK

with the (pseudo) code :

PaymentInformationServiceImple -> PaymentsInformationDAOImple.getPayments(int custId)

I come from some background with component testing in NodeJS (Where i used jest where it was fairly trivial to stub out dependencies for the payments service calling the dao above via a simple reference functions). I'm trying to do the same in Karate and these Java Impl classes where I need to stub out the PaymentInformationDAO in realtime so the component test doesnt turn into an live integration test (ie I dont want to test the actual calls to the databae, but rather stub those out alone while making the /GET call to the service)

Ive been googling this a lot but I've been only finding information such as using wiremock to stub out downstream API calls. In my case, I need to stub out the DAO itself which isn't an API call. How would I approach this?

Upvotes: 2

Views: 73

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Karate works at the HTTP layer so the inner details of a service is normally out of scope. But since Karate is a Java lib behind the scenes, it does work well with Java and for e.g. Spring projects. But the question of how to set up your backend to use a mock instead of the real implementation is out of the scope of Karate.

So my suggestion is that you have to work with the backend team on your mocking approach. If this is a Spring project, it should be pretty trivial - e.g. just passing some env flag on the command-line. If you need a Spring specific example, you can find one here. Tips on mocking dependencies can be found here.

Upvotes: 0

Related Questions