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
Ian Kang 1Ian Kang 1 

how to write a test class to check if a particular System.debug(message); is printed

Hi guys, 

I was just wondering if there is a way to use System.assertEquals(); or anything similiar in test class to check if a particular System.debug(); statement is printed. 

Could you share your trick if you know a way?

Thanks!
Best Answer chosen by Ian Kang 1
Ajay K DubediAjay K Dubedi
Hi Ian,
Read-out the following points it may be helpful for you:
1. The debug statement is always going to be printed if it falls under a particular condition, there is no way to get confirmed that the debug line is printed or not.
2. The best possible way to get the confirmation that the records being inserted or not is to do a sanity check in your test class so that you always have a confirmation that the records are inserted and it is going to cover all the conditions.
3. You can always check your's debug statement in the debug log, there are no other possible ways.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
 

All Answers

Ajay K DubediAjay K Dubedi
Hi Ian,
Read-out the following points it may be helpful for you:
1. The debug statement is always going to be printed if it falls under a particular condition, there is no way to get confirmed that the debug line is printed or not.
2. The best possible way to get the confirmation that the records being inserted or not is to do a sanity check in your test class so that you always have a confirmation that the records are inserted and it is going to cover all the conditions.
3. You can always check your's debug statement in the debug log, there are no other possible ways.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
 
This was selected as the best answer
Deepali KulshresthaDeepali Kulshrestha
Hi Ian, 
You can do this by putting a different message in each System.debug('message') or you can give numbering to each debug log to check if particular debug log is running or not
Just like:
System.debug('One');
System.debug('Two');
..
..
System.debug('Ten');

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.