Writing Pure Apex Unit Testing
In the era of agile software development, with quick releases of small iterations, we should do testing more and more frequently.
Writing Pure Apex Unit Testing
In the era of agile software development, with quick releases of small iterations, we should do testing more and more frequently.
However, Salesforce development world, we focused on writing functional / integration level testing (which combines individual components and tests them as groups) rather than doing pure low level unit testing.

Unit test is the foundation of all other testing, the more pure unit testing we write the more robust software we will produce.
What is unit testing ?
In simple words, testing the smallest piece of your code.
A “good” unit test follows these rules -
- Every independent class should have independent unit test class created. — every function/ method we write should have corresponding unit test for that, if you change that function so that you change unit test method of it as well.
- Writing unit test doesn’t mean testing everything — we should always test the class/ method under test and mock all other integration / dependencies (Unit tests should be self-sufficient), as those dependencies are already tested independently. The main objective of unit testing is to ensure that each individual part is working well and as it’s supposed to work.
Unlike mockito framework from Java development world, we don’t have that flexible robust mocker framework provided in Salesforce. However, Salesforce has provided Stub API for implementing a mocking framework.
Finnacialforce has provided a bunch of good libraries (Stub APIs) using that we can easily write the true apex unit tests.
You can find the sample unit test class implemented using financialforce stub APIs here.
Benefits — Though there are tons of benefits we will get by writing pure unit tests but this is incredibly useful when you have many dependencies with upstream process /systems as it will save a-lot of your unit test development time and tests runs faster as it meant to be.
References —
[embed]Code 4 Cloud Coding for the Force.com Platformcode4cloud.wordpress.com
[embed]
메타데이터
- post_id
- f49db6b9e2b2
- slug
- writing-pure-apex-unit-testing-f49db6b9e2b2
- url
- https://medium.com/@rajkumar.gaikwad3/writing-pure-apex-unit-testing-f49db6b9e2b2
- canonical_url
- https://medium.com/@rajkumar.gaikwad3/writing-pure-apex-unit-testing-f49db6b9e2b2
- author_url
- https://medium.com/@rajkumar.gaikwad3
- status
- ok
- fetched_at
- 2026-07-27 05:39:41