Home > front end >  Salesforce Tests for Org
Salesforce Tests for Org

Time:09-17

Should every APEX class have its own test class?

Currently dealing with tests in an org where 80% of APEX tests are under one test class which does not seem to be the best option.

CodePudding user response:

I would say that yes indeed, having all the org's tests in one single class is not really something recommended. Some of the drawbacks that I see:

  • Big classes increase dependency meaning that is more likely that several developers work on the same class, which increases complexity
  • When one big class contains all the test methods it is harder to functionally "scope" your tests. When an independent class contains test methods for a certain class, it is easier to understand what is trying to be tested and to further extend the class coherently
  • By using different classes you can make better use of the @testSetup annotation (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_testsetup_using.htm) because only one method per class can be annotated with the @testSetup annotation

Those are some of the reasons (among others for sure) why you would prefer to split your test methods in different classes.

CodePudding user response:

I think there is no one answer that suit all situation for this question. It will be on case by case basis.

Since you only have 1 Test Class for your Org. I believe your code base is not that big yet and it is very good time to start introduce Design Pattern that suitable for your use case and refactor that code.

  • Related