4

This is a newbie question.

Let us assume that I have the following test class

@isTest
class xyz
{
  @isTest static void method1() {...code..}
  @isTest static void method2() {...code..}
  @isTest static void method3() {...code..}
}

Questions

a) Is it possible to execute only a specific methods from the above test class ?.

I always execute a test for the whole test class.

Can someone clarify whether it is possible for me to execute only a specific test method ?

b) How are the governor limits' calculation done when the whole class' methods are executed ?

For example we know that SOQL Query limit is 100 per transaction.

Does this 100 SOQL query limit is applied against all the methods (method1,method2 & method3)..or every test method has its own governor limits ?

In the above example what is the SOQL query limit for the whole test class ?

Is it still 100 to be shared across 3 methods or 300 (3 x 100 ..100 for each method) ?

Hope I am clear.

2
  • I really strongly recommend against testing the whole class at once. That will make valuable assertions much more challenging to write, make it more difficult to check edge cases, and make it more difficult to modify the tests if the functionality changes.
    – Adrian Larson
    Jan 20, 2015 at 15:43
  • For part a) You now can execute a single test method using VSCode with Salesforce Extension Pack, you'll get that feature where a grayed out "Run Test" appears on top of every test method and you can click that to run that single method. 🍻
    – Bahman.A
    Dec 31, 2020 at 19:21

1 Answer 1

2

a). No, when you execute a test class, it runs every method in the test class.

b). Governor limits are reset for each test method. In addition, some governor limits are reset in between the Test.startTest() and Test.stopTest() functions used commonly in test methods.

Here's a good guide to getting started with test methods: An Introduction to Apex Code Test Methods

1
  • For part a) You now can execute a single test method using VSCode with Salesforce Extension Pack, you'll get that feature where a grayed out "Run Test" appears on top of every test method and you can click that to run that single method. 🍻
    – Bahman.A
    Dec 31, 2020 at 19:21

You must log in to answer this question.

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