Home > front end >  How to write Integration test for a microservice if it calling another microservice
How to write Integration test for a microservice if it calling another microservice

Time:12-01

I am writing an Integration Test(after here refer as IT)for my feature. In my requirement i need to call another service to update the data.these services cant be run locally so cant run Postman. SO only i am allow to use IT.

EX. I have 2 services serviceA and serviceB , in microservice serviceA , I am writing code my feature logic and to update some data in DB(another schema for serviceB) i need to call serviceB. I have written the code in A and now i am making a call

public void addUToG(UGT ugt, String accessToken)  {
    try {
        String url = ServiceB_Baseurl   "/"   id   "/works";
        HttpResponse response = httpUtil.putRequest(url, accessToken,
                ContentType.APPLICATION_JSON.toString(),
                mapper.writeValueAsString(ugt));
        if (response != null && response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            logger.warn("Failed ");
        }
    }
    catch(Exception e) {
        logger.warn("Exception ", e);
    }
}

Here I making a call to other service, but i need to test this with IT and I cant run postman as these services cant be run locally. So i have no idea what can i do to test it ?Any suggestions would be great help.

TIA

  • Related