+ Start a Discussion
AlexPHPAlexPHP 

How to run a single (one) test class in Production environment

Hey guys

 

I am trying to debug an issue with deploying files to a production instance.  In doing so, I want to run a single test class in order to examine the debug log.

 

However, when I do Force.com -> Run Tests on the test class that I want, the debug log shows the log for all unit tests for some reason.  Because of this, the log quickly is filled up and is truncated with the note:

 

*********** MAXIMUM DEBUG LOG SIZE REACHED ***********

... and therefore I am unable to see the log for the test class that I selected.

 

How can I run a single test class in a Production environment so that I can view log for just that class?

Best Answer chosen by Admin (Salesforce Developers) 
Cool_DevloperCool_Devloper

Are you by any chance clicking on "Run All Tests" from the Apex Classes home page? As, only in that case, debug logs for all the classes are shown.

If you running the test for a single class by going to the view screen of the class and clicking on the Run Test button, it should only execute the tests for that particular class!

Cool_D

All Answers

Cool_DevloperCool_Devloper

Are you by any chance clicking on "Run All Tests" from the Apex Classes home page? As, only in that case, debug logs for all the classes are shown.

If you running the test for a single class by going to the view screen of the class and clicking on the Run Test button, it should only execute the tests for that particular class!

Cool_D

This was selected as the best answer
AlexPHPAlexPHP

No, I am not clicking on "Run All Tests" from the Apex Classes home page.  As mentioned, I am trying to debug an issue with deploying files to a production instance from the Force.com IDE.


When trying to save the file to the server, I keep getting:

Save error: Unable to perform save on all files: An unexpected error has occurred. Please try again, or check the log file for details.

 Therefore, the files have not yet hit the production server for me to be able to "Run Test" from the single class screen on salesforce.com.

 

So in order to try to debug the issue, I wanted to view the log file of one of my test classes that is not running cleanly. 

 

I am trying to do this through the Force.com IDE by right-clicking on the test class -> Force.com -> Run Tests. However, I am unable to do this because the log file looks like it contains the debug log of all tests... which quickly becomes filled up and trunctated with the message:

*********** MAXIMUM DEBUG LOG SIZE REACHED ***********

 Please help, thank you!

 

Message Edited by AlexPHP on 11-19-2009 12:29 PM
Kirk F.ax361Kirk F.ax361

This should not be marked as the solution, but it may be a workaround for you:  try changing the name of your test class so it runs first, before you run out of log text.

 

For example, if you have a custom object Xray__c, and a trigger that runs on it Xray_trigger, and a test class called Xray_TestClass, then (in my experience) this test class may be called almost last.  Test classes seem to be called in alphabetical order (someone correct me, please).

 

In this example, if my debugging info that comes from the Xray_TestClass doesn't make it into the log, I'll deploy a new test class:  AAA_Xray_TestClass.  This changes it's alpha order, so it may be called earlier.

 

(Hint:  once you've found the problem, remember to delete the "AAA_..." test class.  Otherwise you and all the other developers might wind up climbing over each other to be the first alphabetically-called test class... "AAAAAAAAA_Xray_TestClass" etc.  Be a good neighbor, and clean up after yourself.  ;-)

 

This has helped me once.  I'd be interested if it helps others.