06-29-2021 03:34 AM
I am following APS Junit for testing aps custom logic.
I have JavaDelegate and signal class.
I have custom endpoint which is calling third party api to fetch data, for that How Can I create UNIT Test case? without using Integration Testing and Using Mockito.
Any help would be appreciated.
Thanks&Regards,
Laxmi Mounika Boorela
06-29-2021 07:12 AM
I would just mock a sample response into mockito unit test case. In mockito framework its all about mocking, so if a service is expecting some response from third party or from a web url, we just mock a sample response to valiate all positive/negative test scenarios.
Example:
public void testBlah() throws Exception { ....... ...... final String endPoint = "https://example.com/getJson/xyzabc123"; when(blahService.getJson(endPoint)) .thenReturn(new JSONObject(getMockedResourceAsString("/files/test-sample.json"))); ..... ..... }
Explore our Alfresco products with the links below. Use labels to filter content by product module.