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
Haystack CertifiedHaystack Certified 

Test class for class using ApexTestQueueItem

I am using the AutomatedTestJobQueuer class mentioned in this article to execute all test classes via apex on a schedule.

http://developer.force.com/cookbook/recipe/automated-unit-test-execution

It uses ApexTestQueueItem object to execute each test class.  I need to write a test class for AutomatedTestJobQueuer, but get this error on Line 63 where it tries to insert the test request:

"System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Apex tests cannot be enqueued during a test.: []"

Anyone know of a way to get around this?
Amit Chaudhary 8Amit Chaudhary 8
It look like your apex test class is already runing and you are again scheduling that. Please Abord all Test classess and try again.
Mahesh DMahesh D
Please provide your "AutomatedTestJobQueuer" class code so that I will try to provide the answer.

You may need to use Test.isRuningTest() method.

Regards,
Mahesh
Haystack CertifiedHaystack Certified
Amit, I checked that there were no tests running.  I also updated the code so that the test class doesn't call itself.  I still get the same error.

Mahesh, the code is the link.