function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phil WPhil W 

How can I write a method in a managed package apex class that can only be called from a test method outside the package?

I have a global class, A, in my managed package that must only be instantiated by my managed package code. The instance is intended to then be passed to a method in a (global) interface, I, that is to be implemented outside the managed package.

Now, in order to test the interface implementation, E, I need the test to be able to create an instance of A to pass into E's implementation of I's method.

I tried creating a @TestVisible private constructor for A that accepts the required test setup parameters and using that in E's test class, but that didn't work.

Has anyone got any suggestions?