Use the SAP Cloud SDK for Java to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
22
stars
14
forks
source link
How to Mock getDestination for Unit Testing Java Methods with HTTP Requests? #577
I’m working on unit testing a Java method that interacts with external HTTP destinations and performs HTTP requests. I’m having difficulty covering the method with JUnit tests due to its dependencies on external services.
I’m working on unit testing a Java method that interacts with external HTTP destinations and performs HTTP requests. I’m having difficulty covering the method with JUnit tests due to its dependencies on external services.
Here is the method I need to test:
My challenges:
Mocking getDestination(destinationName()).asHttp(): How can I mock the destination and its properties?
What I’ve tried:
I attempted to use Mockito for mocking, but I'm unsure how to properly mock the getDestination and HttpClient methods.
junits I tried:
This junits throws error:
Destination Access exception: failed to get destination