I believe I've found a bug, but I wanted to throw it to the community to see if I'm not understanding something. I'm implementing a test class and using Test.createStub to mock a dependency. The interface being mocked is essentially:

public interface IBatchableFactory {
  Database.Batchable<SObject> getBatchable(String someParam);

My test method invokes:

public IBatchableFactory setupDependencies() {
  StubProvider myStubProvider = new BatchableStubProvider();
  IBatchableFactory factStub = (IBatchableFactory) Test.createStub(IBatchableFactory.class, myStubProvider);

  return factStub;

My test fails on the line creating factStub.

The error is:

System.TypeException: No type arguments provided for a parameterized type: Database.Batchable

The top of the stack trace is:

Class.System.Test.createStub: line 93, column 1

That's a system method I have no control over! I am 100% confident the problem is not within the stub provider itself, either.

Has anyone ever seen / solved this problem?

1 Answer 1


Unfortunately you've found one of the current limitations of the stub api.


Apex Stub API Limitations

Keep the following limitations in mind when working with the Apex stub API.

The object being mocked must be in the same namespace as the call to the Test.createStub() method. However, the implementation of the StubProvider interface can be in another namespace.

You can’t mock the following Apex elements.

  • Static methods (including future methods)
  • Private methods
  • Properties (getters and setters)
  • Triggers
  • Inner classes
  • System types
  • Classes that implement the Batchable interface
  • Classes that have only private constructors

Iterators can’t be used as return types or parameter types.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .