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

Apex & unit tests


What is best way to write unit tests for an Apex class ? The known options are listed below.
1. Write the test in seperate Apex class.
2. Write test in an inner class in the same apex class.
3. Write test same apex class at the bottom.

I used option 1, but had a problem with writing tests for private methods. Finally I had to make all of them public, which I don't think as not good practise.

Can I use @IsTest annotation for inner class or test methods ?


Jon Mountjoy_Jon Mountjoy_
Hi Viraj

That's a great question you raise.  We've just published an article on test methods:
An Introduction to Apex Code Test Methods

I've just asked the author if he can look at some of your questions as well.  You make a good point about the testing of private methods....

Hi Jon

Thank you very much for your feedback.

Is there any resolution to this problem yet? I have seen no examples of testing private methods so far - which makes either private methods or testing them impossible.