cancel
Showing results for 
Search instead for 
Did you mean: 

JUNIT test for custom rest Endpoint using Mockito

Laxmi
Champ in-the-making
Champ in-the-making

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

1 REPLY 1

abhinavmishra14
World-Class Innovator
World-Class Innovator

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")));
    	.....
        .....		
}
~Abhinav
(ACSCE, AWS SAA, Azure Admin)