We are thinking of creating some smart monkey tests. Basing this on @isTest Apex tests seems obvious, but we would need to record the random factors (a few random numbers) used in each test. It is my understanding that as database changes are rolled back and web service calls have to be mocked in tests, there is no way to add such information to the test output. So @isTest Apex tests is probably not the way to go.

Or am I missing something?

2 Answers 2


You are correct that everything is rolled back when an apex test completes (apart from autonumbers, though that can be avoided come Spring 14 also).

If it was acceptable for this to be a two-stage process, you could generate the random values prior to executing the unit tests and store them in a static resource - that would allow you to use the Test.loadData() method:


to load the values into a custom object that your tests could then access. This would likely require some manual intervention though, as you can't create a static resource through Apex.


The only two ways I've found to retrieve any data from a test are:

  • Throwing an exception. You can even programmatically recover that exception by looking at the ApexTestResult SObject. The information sent is obviously limited. Also, this forces to make your test fail.
  • Adding information to the debug log. Is it however not possible to access the log in apex. You would need to recover it and parse it in another language outside of Salesforce.
  • Hand't realized there was a queryable ApexTestResult objects - thanks.
    – Keith C
    Commented Feb 27, 2014 at 21:16

You must log in to answer this question.

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