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
sankumsankum 

whit is use of test triggers by writing test class

hi iam new for salesforce

now i want know why we need the test the trigger in test class?

 

 

we are testing triggers in UI mode

then y need to write the test class for triggers?

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

Just to add some additional details around testing (empuc did a good job above).

 

Performing Unit Testing is not specific to just the Force.com platform. Yes, Force.com requires test coverage as part of the platform, but Unit Testing is part of a well defined Software Development Lifecycle (SDLC) regardless of technology. Due to the multi-tenant archicteture of Force.com Unit Tests are required by the platform which is a good thing.

 

Building proper test classes with best practices (Data Independence, System Assertions, Bulkified Tests, etc) help ensure that your application is behaving properly and will do so when you deploy from one environement to another.

 

Simply testing in the UI is not acceptable for any technology. Yes UI testing is important, and tools like Selenium and others can script UI tests. But in the instance of Apex Triggers for example, Triggers execute at the Database level. They don't have to be executed via a UI, they can be executed by Data Loader, API calls, etc. Anything that updates the database which doesn't always occur in the UI.

 

You need to be able to automate your unit tests and ensure they are repeatable as part of your build process.

 

Please see the below link for best practices for writing unit tests which should hopefully help you on your path to learning Force.com.

 

http://wiki.developerforce.com/page/How_to_Write_Good_Unit_Tests

 

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

 

All Answers

empucempuc

Idea of writing test classes - no matter whether they are build to support classes or triggers is to make sure that everything is working as you planned on the beginning.  Thats why based on prepared test data which you should create on your testing methods you need to test all scenario and all paths of going through the code which you have wrote.

 

It is also important to have some checkpoints in your test methods which will use System.assert statments to verify whether the partial result of processing the code is the same as you've planned. 

 

Imagine that after building some custom mechanism based on trigger which process CustomObject1 later on someone adds a new trigger mechanism to its ParrentObject. It may happened that those mechanism will influence each other causing different results than the one You have planned on the beginning. When test methods are properly written, your organization will be notified when some exceptions will occur... 

 

I hope it will help ya to understand the idea of test methods, which can be a pain in the ass but afterwards they can really save you a lot of time and presesrve you from deploying the changes which causes some damage in your existing code.

 

Best regards

Cory CowgillCory Cowgill

Just to add some additional details around testing (empuc did a good job above).

 

Performing Unit Testing is not specific to just the Force.com platform. Yes, Force.com requires test coverage as part of the platform, but Unit Testing is part of a well defined Software Development Lifecycle (SDLC) regardless of technology. Due to the multi-tenant archicteture of Force.com Unit Tests are required by the platform which is a good thing.

 

Building proper test classes with best practices (Data Independence, System Assertions, Bulkified Tests, etc) help ensure that your application is behaving properly and will do so when you deploy from one environement to another.

 

Simply testing in the UI is not acceptable for any technology. Yes UI testing is important, and tools like Selenium and others can script UI tests. But in the instance of Apex Triggers for example, Triggers execute at the Database level. They don't have to be executed via a UI, they can be executed by Data Loader, API calls, etc. Anything that updates the database which doesn't always occur in the UI.

 

You need to be able to automate your unit tests and ensure they are repeatable as part of your build process.

 

Please see the below link for best practices for writing unit tests which should hopefully help you on your path to learning Force.com.

 

http://wiki.developerforce.com/page/How_to_Write_Good_Unit_Tests

 

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

 

This was selected as the best answer
sankumsankum

thans for spending your valuable time

 

 

sankumsankum

thanks for spending valuble time..