+ Start a Discussion
ElectronElectron 

About Set Up all Conditions for Testing, what's all conditions mean?

Hi everyone,

 

I made one APEX trigger, and I  read this article to learn how to write unit test http://wiki.developerforce.com/page/How_to_Write_Good_Unit_Tests
It said we need Set Up All Conditions For Testing, what it means?
 
There are several conditional statements in my trigger.
Let me make one example that we use record type to limit the trigger.
Should I 
 
1.
I initialize a test contact, test one record type, then change its record type then test it and use system.assert.
 
Or 
 
2.
It's based on how many update action to the database, like there are 4 update in my trigger, I should cover these 4.
 
I am new to APEX, and thank you for answering my question.
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This means that you shouldn't rely on any data already present in the system, rather you should set up all of your own data from scratch.

 

If you have four conditions in your code that cause different processing to take place, you should be writing at least 5 unit test methods - one each to satisfy the four conditions and check the correct processing took place, and one that doesn't satisfy any condition, so you can check that no processing takes place in that scenario.