Junit - Mocking Service Calls - How to make sure that No External calls are being made

Unit Test should be such that they are self dependent and not dependent on the external systems / integrations to verify the accuracy of the unit function and logic. Hence many a times we mock the external applications / service call so that they are not dependent.

Many a times Junit would pass even if we are making actual service calls  and just verifying if the calls are being made. In those cases , though your Junit may work fine today but will create problem once those services , applications won't be active. In such situation all Junits would fail and will give a wrong picture about the logic consistency of your code units.

So, How to make sure that all service / external application calls have been mocked ?

Step 1 - Make sure that no application / Services are running on your Machine. 

Step 2 - Stop all Servers in your workspace.

Step 3 - Disconnect your network cable so that it shouldn't make any call over network.

Step 4 - Execute your Junits again and see the result.

All Junits still passing will make sure that all Junits are self dependent.

Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus