When you create an Apex class from a WSDL, the methods in the auto-generated class call <samp>WebServiceCallout.invoke</samp>, which performs the callout to the external service. When testing these methods, you can instruct the Apex runtime to generate a fake response whenever <samp>WebServiceCallout.invoke</samp> is called. To do so, implement the <samp>WebServiceMock</samp>interface and specify a fake response for the Apex runtime to send. Here are the steps in more detail.
First, implement the <samp>WebServiceMock</samp> interface and specify the fake response in the <samp>doInvoke</samp> method.