Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm#apex_System_Test_loadData

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.

share|improve this answer
add comment

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.
share|improve this answer
    
Hand't realized there was a queryable ApexTestResult objects - thanks. –  Keith C Feb 27 at 21:16
    
Very creative! Thanks for sharing. –  user320 Feb 27 at 21:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.