You can define the behavior of stub objects, which are created at runtime as anonymous subclasses of Apex classes. The stub API comprises the System.StubProvider interface and the System.Test.createStub() method.
- Define the behavior of the stub class by implementing the System.StubProvider interface.
- Instantiate a stub object by using the System.Test.createStub() method.
- Invoke the relevant method of the stub object from within a test class.
This GA version resolves the following limitations that were present in the pilot version of the stub API.
- When calling the createStub() method in the pilot version, your Apex class was required to have a constructor that took zero arguments. This limitation is no longer present in the GA version.
- You can now mock exceptions.
- You can now mock classes that implement the Schedulable and Queueable interfaces.